refactor(SQL): Staging tables and Calc stored procedures used for modular stored procedure archicture for scalability. Implemented for Product Catalogue. \n BREAKING CHANGE: BIT argument a_debug added to all but basic stored procedures for analysis of performance and results.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,9 @@
|
||||
|
||||
|
||||
# Drop dependencies
|
||||
DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Calc_User;
|
||||
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_Region;
|
||||
@@ -12,7 +14,8 @@ DROP TABLE IF EXISTS tmp_Region;
|
||||
DROP TABLE IF EXISTS tmp_Shop_User;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Order;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_User_Eval;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Image;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Variation;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Discount;
|
||||
@@ -35,6 +38,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 Shop_Calc_User_Temp;
|
||||
|
||||
DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Temp;
|
||||
DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Audit;
|
||||
DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link;
|
||||
@@ -223,8 +229,10 @@ DROP PROCEDURE IF EXISTS p_clear_split_temp;
|
||||
|
||||
DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name;
|
||||
|
||||
DROP PROCEDURE IF EXISTS p_shop_user_eval;
|
||||
DROP PROCEDURE IF EXISTS p_clear_shop_user_eval_temp;
|
||||
DROP PROCEDURE IF EXISTS p_shop_calc_user;
|
||||
DROP PROCEDURE IF EXISTS p_shop_calc_user;
|
||||
DROP PROCEDURE IF EXISTS p_shop_clear_user_eval_temp;
|
||||
DROP PROCEDURE IF EXISTS p_shop_clear_calc_user;
|
||||
|
||||
DROP PROCEDURE IF EXISTS p_shop_get_many_access_level;
|
||||
DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement;
|
||||
|
||||
26
static/MySQL/1000_tbl_Shop_Calc_User_Temp.sql
Normal file
26
static/MySQL/1000_tbl_Shop_Calc_User_Temp.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
# Calc User Staging
|
||||
-- USE partsltd_prod;
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
|
||||
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Calc_User_Temp';
|
||||
|
||||
CREATE TABLE Shop_Calc_User_Temp (
|
||||
-- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
guid BINARY(36) NOT NULL,
|
||||
id_user INT NULL,
|
||||
id_permission_required INT NOT NULL,
|
||||
CONSTRAINT FK_Shop_Calc_User_Temp_id_permission_required
|
||||
FOREIGN KEY (id_permission_required)
|
||||
REFERENCES partsltd_prod.Shop_Permission (id_permission),
|
||||
priority_access_level_required INT NOT NULL,
|
||||
id_product INT NULL,
|
||||
CONSTRAINT FK_Shop_Calc_User_Temp_id_product
|
||||
FOREIGN KEY (id_product)
|
||||
REFERENCES partsltd_prod.Shop_Product (id_product),
|
||||
is_super_user BIT NULL,
|
||||
priority_access_level_user INT NULL,
|
||||
can_view BIT,
|
||||
can_edit BIT,
|
||||
can_admin BIT
|
||||
);
|
||||
12
static/MySQL/1000_tbl_Split_Temp.sql
Normal file
12
static/MySQL/1000_tbl_Split_Temp.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
# Split Staging
|
||||
-- USE partsltd_prod;
|
||||
-- DROP TABLE IF EXISTS Split_Temp;
|
||||
|
||||
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Split_Temp';
|
||||
|
||||
CREATE TABLE Split_Temp (
|
||||
guid BINARY(36) NOT NULL
|
||||
, display_order INT NOT NULL
|
||||
, substring VARCHAR(4000) NOT NULL
|
||||
);
|
||||
@@ -10,8 +10,11 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Category_Temp (
|
||||
, code VARCHAR(50) NOT NULL
|
||||
, name VARCHAR(255) NOT NULL
|
||||
, description VARCHAR(4000) NULL
|
||||
, active BIT NOT NULL
|
||||
, display_order INT NOT NULL
|
||||
, id_access_level_required INT NOT NULL DEFAULT 1
|
||||
, display_order INT NOT NULL
|
||||
, active BIT NOT NULL
|
||||
, can_view BIT NULL DEFAULT NULL
|
||||
, can_edit BIT NULL DEFAULT NULL
|
||||
, can_admin BIT NULL DEFAULT NULL
|
||||
, guid BINARY(36) NOT NULL
|
||||
);
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
|
||||
# Products Temp
|
||||
|
||||
|
||||
-- DROP TABLE IF EXISTS Shop_Product_Temp;
|
||||
|
||||
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Temp';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Shop_Product_Temp (
|
||||
id_product INT NOT NULL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
id_category INT NOT NULL,
|
||||
has_variations BIT NOT NULL,
|
||||
id_access_level_required INT NOT NULL,
|
||||
active BIT NOT NULL DEFAULT 1,
|
||||
display_order INT NOT NULL,
|
||||
created_on TIMESTAMP,
|
||||
created_by INT
|
||||
id_product INT NOT NULL
|
||||
, name VARCHAR(255) NOT NULL
|
||||
, id_category INT NOT NULL
|
||||
, has_variations BIT NOT NULL
|
||||
, id_access_level_required INT NOT NULL
|
||||
, display_order INT NOT NULL
|
||||
, active BIT NOT NULL DEFAULT 1
|
||||
, can_view BIT NULL DEFAULT NULL
|
||||
, can_edit BIT NULL DEFAULT NULL
|
||||
, can_admin BIT NULL DEFAULT NULL
|
||||
, guid BINARY(36) NOT NULL
|
||||
);
|
||||
|
||||
@@ -1,44 +1,34 @@
|
||||
|
||||
# Product Permutation Temp
|
||||
|
||||
|
||||
-- DROP TABLE IF EXISTS Shop_Product_Permutation_Temp;
|
||||
|
||||
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Temp';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Temp (
|
||||
id_permutation INT NOT NULL PRIMARY KEY,
|
||||
id_product INT NOT NULL,
|
||||
CONSTRAINT FK_Shop_Product_Permutation_Temp_id_product
|
||||
FOREIGN KEY (id_product)
|
||||
REFERENCES Shop_Product(id_product)
|
||||
ON UPDATE RESTRICT,
|
||||
description VARCHAR(4000) NOT NULL,
|
||||
cost_local FLOAT NOT NULL,
|
||||
id_currency_cost INT NOT NULL,
|
||||
profit_local_min FLOAT NOT NULL,
|
||||
latency_manufacture_days INT NOT NULL,
|
||||
id_unit_measurement_quantity INT NOT NULL,
|
||||
CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_quantity
|
||||
FOREIGN KEY (id_unit_measurement_quantity)
|
||||
REFERENCES Shop_Unit_Measurement(id_unit_measurement),
|
||||
count_unit_measurement_per_quantity_step FLOAT NOT NULL,
|
||||
quantity_min FLOAT NOT NULL,
|
||||
quantity_max FLOAT NOT NULL,
|
||||
quantity_stock FLOAT NULL,
|
||||
is_subscription BIT NOT NULL,
|
||||
id_unit_measurement_interval_recurrence INT,
|
||||
CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_recurrence
|
||||
FOREIGN KEY (id_unit_measurement_interval_recurrence)
|
||||
REFERENCES Shop_Unit_Measurement(id_unit_measurement),
|
||||
count_interval_recurrence INT,
|
||||
id_stripe_product VARCHAR(100) NULL,
|
||||
does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0,
|
||||
id_unit_measurement_interval_expiration_unsealed INT,
|
||||
CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_expiration
|
||||
FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed)
|
||||
REFERENCES Shop_Unit_Measurement(id_unit_measurement),
|
||||
count_interval_expiration_unsealed INT,
|
||||
active BIT NOT NULL DEFAULT 1,
|
||||
-- display_order INT NOT NULL,
|
||||
guid BINARY(36)
|
||||
id_permutation INT NOT NULL
|
||||
, id_product INT NOT NULL
|
||||
, description VARCHAR(4000) NOT NULL
|
||||
, cost_local FLOAT NOT NULL
|
||||
, id_currency_cost INT NOT NULL
|
||||
, profit_local_min FLOAT NOT NULL
|
||||
, latency_manufacture_days INT NOT NULL
|
||||
, id_unit_measurement_quantity INT NOT NULL
|
||||
, count_unit_measurement_per_quantity_step FLOAT NOT NULL
|
||||
, quantity_min FLOAT NOT NULL
|
||||
, quantity_max FLOAT NOT NULL
|
||||
, quantity_stock FLOAT NULL
|
||||
, is_subscription BIT NOT NULL
|
||||
, id_unit_measurement_interval_recurrence INT
|
||||
, count_interval_recurrence INT
|
||||
, id_stripe_product VARCHAR(100) NULL
|
||||
, does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0
|
||||
, id_unit_measurement_interval_expiration_unsealed INT
|
||||
, count_interval_expiration_unsealed INT
|
||||
, active BIT NOT NULL DEFAULT 1
|
||||
-- display_order INT NOT NULL
|
||||
, guid BINARY(36)
|
||||
, can_view BIT NULL DEFAULT NULL
|
||||
, can_edit BIT NULL DEFAULT NULL
|
||||
, can_admin BIT NULL DEFAULT NULL
|
||||
);
|
||||
|
||||
45
static/MySQL/6000_p_debug_timing_reporting.sql
Normal file
45
static/MySQL/6000_p_debug_timing_reporting.sql
Normal file
@@ -0,0 +1,45 @@
|
||||
-- USE partsltd_prod;
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_debug_timing_reporting;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_debug_timing_reporting (
|
||||
IN a_time_start TIMESTAMP(6)
|
||||
)
|
||||
BEGIN
|
||||
/*
|
||||
PROCEDURE p_debug_timing_reporting
|
||||
Shared method timing reporting
|
||||
*/
|
||||
DECLARE v_time_end TIMESTAMP(6);
|
||||
|
||||
SET v_time_end := CURRENT_TIMESTAMP(6);
|
||||
SELECT
|
||||
a_time_start
|
||||
, UNIX_TIMESTAMP(a_time_start)
|
||||
, MICROSECOND(a_time_start) / 1000
|
||||
, v_time_end
|
||||
, UNIX_TIMESTAMP(v_time_end)
|
||||
, MICROSECOND(v_time_end) / 1000
|
||||
, v_time_end - a_time_start AS timestamp_delta
|
||||
, UNIX_TIMESTAMP(v_time_end - a_time_start) AS UNIX_TIMESTAMP_timestamp_delta
|
||||
, MICROSECOND(v_time_end - a_time_start) AS MICROSECOND_timestamp_delta
|
||||
-- , TIME_FORMAT(TIMEDIFF(v_time_end, a_time_start), '%H:%i:%s') AS time_difference
|
||||
, CONCAT(
|
||||
TIME_FORMAT(TIMEDIFF(v_time_end, a_time_start), '%H hours, %i minutes, %s seconds'),
|
||||
', ',
|
||||
TIMESTAMPDIFF(MICROSECOND, a_time_start, v_time_end) % 1000000 / 1000, ' milliseconds'
|
||||
) AS time_difference
|
||||
;
|
||||
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CALL partsltd_prod.p_debug_timing_reporting (
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
*/
|
||||
@@ -1,52 +1,47 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
CALL p_split (
|
||||
'noods, chees',
|
||||
','
|
||||
)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_split;
|
||||
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_split (
|
||||
IN a_string VARCHAR(4000),
|
||||
IN a_separator VARCHAR(5)
|
||||
IN a_guid BINARY(36)
|
||||
, IN a_string LONGTEXT
|
||||
, IN a_separator VARCHAR(1000)
|
||||
-- IN a_allow_empty BIT
|
||||
, IN a_debug BIT
|
||||
)
|
||||
BEGIN
|
||||
-- Argument redeclaration
|
||||
-- Variable declaration
|
||||
DECLARE v_has_string BIT;
|
||||
DECLARE v_has_separator BIT;
|
||||
DECLARE v_i_separator INT;
|
||||
DECLARE v_i_start INT;
|
||||
DECLARE v_i_end INT;
|
||||
DECLARE v_current_item VARCHAR(4000);
|
||||
DECLARE v_time_start TIMESTAMP(6);
|
||||
|
||||
|
||||
-- Argument validation + default values
|
||||
SET v_time_start := CURRENT_TIMESTAMP(6);
|
||||
SET a_string := IFNULL(a_string, '');
|
||||
SET a_separator := IFNULL(a_separator, '');
|
||||
SET a_debug := IFNULL(a_debug, 0);
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT
|
||||
a_guid
|
||||
, a_string
|
||||
, a_separator
|
||||
, a_debug
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- Temporary tables
|
||||
DROP TABLE IF EXISTS Split_Temp;
|
||||
CALL p_validate_guid ( a_guid );
|
||||
|
||||
CREATE TABLE Split_Temp (
|
||||
DROP TABLE IF EXISTS tmp_Split_Split;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Split_Split (
|
||||
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
substring VARCHAR(4000) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
-- Parse filters
|
||||
SET v_has_string = CASE WHEN a_string = '' THEN 0 ELSE 1 END;
|
||||
SET v_has_separator = CASE WHEN a_separator = '' THEN 0 ELSE 1 END;
|
||||
|
||||
@@ -57,40 +52,51 @@ BEGIN
|
||||
|
||||
WHILE v_i_end > 0 DO
|
||||
SET v_current_item = SUBSTRING(a_string, v_i_start, v_i_end - v_i_start);
|
||||
INSERT INTO Split_Temp (substring) VALUES (v_current_item);
|
||||
INSERT INTO tmp_Split_Split (substring) VALUES (v_current_item);
|
||||
|
||||
SET v_i_start = v_i_end + 1;
|
||||
SET v_i_end = LOCATE(',', a_string, v_i_start);
|
||||
END WHILE;
|
||||
|
||||
SET v_current_item = SUBSTRING(a_string, v_i_start);
|
||||
INSERT INTO Split_Temp (substring) VALUES (TRIM(v_current_item));
|
||||
INSERT INTO tmp_Split_Split (substring) VALUES (TRIM(v_current_item));
|
||||
END IF;
|
||||
|
||||
/*
|
||||
-- Select the results from the temporary table
|
||||
SELECT * FROM Split_Temp;
|
||||
|
||||
# Return arguments for test
|
||||
SELECT
|
||||
a_string,
|
||||
a_separator
|
||||
-- a_allow_empty
|
||||
;
|
||||
*/
|
||||
IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN
|
||||
START TRANSACTION;
|
||||
INSERT INTO Split_Temp (
|
||||
guid
|
||||
, display_order
|
||||
, substring
|
||||
)
|
||||
SELECT
|
||||
a_guid
|
||||
, display_order
|
||||
, substring
|
||||
FROM tmp_Split_Split
|
||||
;
|
||||
COMMIT;
|
||||
END IF;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
CALL p_debug_timing_reporting ( v_time_start );
|
||||
END IF;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
CALL p_split (
|
||||
'noods, cheese ', # a_string
|
||||
',' # a_separator
|
||||
'nips'
|
||||
, 'noods, cheese ' # a_string
|
||||
, ',' # a_separator
|
||||
# '0', # a_allow_empty
|
||||
, 1
|
||||
);
|
||||
|
||||
SELECT *
|
||||
FROM SPLIT_TEMP;
|
||||
FROM Split_Temp
|
||||
WHERE GUID = 'nips';
|
||||
|
||||
CALL p_clear_split_temp( 'nips' );
|
||||
*/
|
||||
|
||||
@@ -5,11 +5,17 @@ DROP PROCEDURE IF EXISTS p_clear_split_temp;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_clear_split_temp (
|
||||
IN a_guid BINARY(36)
|
||||
)
|
||||
BEGIN
|
||||
CALL p_validate_guid( a_guid );
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
DROP TABLE Split_Temp;
|
||||
-- DROP TABLE IF EXISTS
|
||||
DELETE FROM Split_Temp
|
||||
WHERE GUID = a_guid
|
||||
;
|
||||
|
||||
COMMIT;
|
||||
END //
|
||||
@@ -17,11 +23,7 @@ DELIMITER ;;
|
||||
|
||||
/*
|
||||
|
||||
CALL p_clear_shop_user_eval_temp (
|
||||
'noods, cheese ' # a_guid
|
||||
);
|
||||
CALL p_clear_split_temp ( 'nips' );
|
||||
|
||||
SELECT *
|
||||
FROM Shop_User_Eval_Temp;
|
||||
|
||||
*/
|
||||
|
||||
59
static/MySQL/6001_p_validate_guid.sql
Normal file
59
static/MySQL/6001_p_validate_guid.sql
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS p_validate_guid;
|
||||
DROP PROCEDURE IF EXISTS p_validate_guid_test;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_validate_guid (
|
||||
IN a_guid BINARY(36)
|
||||
-- , IN a_debug BIT
|
||||
)
|
||||
BEGIN
|
||||
/*
|
||||
DECLARE v_code_type_error_bad_data VARCHAR(200);
|
||||
DECLARE v_id_type_error_bad_data INT;
|
||||
|
||||
IF ISNULL(a_guid) THEN
|
||||
SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA');
|
||||
SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data);
|
||||
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
v_id_type_error_bad_data
|
||||
, v_code_type_error_bad_data
|
||||
, 'GUID is required.'
|
||||
;
|
||||
END IF;
|
||||
*/
|
||||
IF ISNULL(a_guid) THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'GUID is required.'
|
||||
;
|
||||
END IF;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_validate_guid_test ()
|
||||
BEGIN
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
|
||||
id_type INT
|
||||
, code VARCHAR(200)
|
||||
, msg TEXT
|
||||
);
|
||||
|
||||
CALL p_validate_guid ( 'nips' );
|
||||
CALL p_validate_guid ( NULL );
|
||||
|
||||
SELECT * FROM tmp_Msg_Error;
|
||||
|
||||
DROP TABLE tmp_Msg_Error;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
CALL p_validate_guid_test();
|
||||
539
static/MySQL/6500_p_shop_calc_user.sql
Normal file
539
static/MySQL/6500_p_shop_calc_user.sql
Normal file
@@ -0,0 +1,539 @@
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_user_eval;
|
||||
DROP PROCEDURE IF EXISTS p_shop_calc_user;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_calc_user (
|
||||
IN a_guid BINARY(36)
|
||||
, IN a_ids_user TEXT
|
||||
, IN a_get_inactive_user BIT
|
||||
, IN a_ids_permission VARCHAR(4000)
|
||||
, IN a_ids_access_level VARCHAR(4000)
|
||||
, IN a_ids_product TEXT
|
||||
, IN a_debug BIT
|
||||
)
|
||||
BEGIN
|
||||
-- Variable declaration
|
||||
DECLARE v_has_filter_permission BIT;
|
||||
DECLARE v_has_filter_user BIT;
|
||||
DECLARE v_has_filter_access_level BIT;
|
||||
-- DECLARE v_has_filter_permutation BIT;
|
||||
DECLARE v_has_filter_product BIT;
|
||||
DECLARE v_id_permission_product INT;
|
||||
DECLARE v_id_permission INT;
|
||||
-- DECLARE v_ids_product VARCHAR(500);
|
||||
DECLARE v_id_access_level_view INT;
|
||||
# DECLARE v_id_access_level_product_required INT;
|
||||
DECLARE v_priority_access_level_view INT;
|
||||
DECLARE v_priority_access_level_edit INT;
|
||||
DECLARE v_priority_access_level_admin INT;
|
||||
DECLARE v_id_access_level INT;
|
||||
DECLARE v_priority_access_level INT;
|
||||
DECLARE v_time_start TIMESTAMP(6);
|
||||
DECLARE v_ids_row_delete VARCHAR(500);
|
||||
DECLARE v_code_type_error_bad_data VARCHAR(200);
|
||||
DECLARE v_id_type_error_bad_data INT;
|
||||
DECLARE v_code_error_permission VARCHAR(200);
|
||||
DECLARE v_id_permission_required INT;
|
||||
|
||||
SET v_time_start := CURRENT_TIMESTAMP(6);
|
||||
SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA');
|
||||
SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data);
|
||||
|
||||
SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2);
|
||||
|
||||
CALL partsltd_prod.p_validate_guid ( a_guid );
|
||||
SET a_ids_user := TRIM(IFNULL(a_ids_user, ''));
|
||||
SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0);
|
||||
SET a_ids_permission := TRIM(IFNULL(a_ids_permission, ''));
|
||||
SET a_ids_access_level := TRIM(IFNULL(a_ids_access_level, ''));
|
||||
SET a_ids_product := TRIM(IFNULL(a_ids_product, ''));
|
||||
SET a_debug := IFNULL(a_debug, 0);
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT
|
||||
a_guid
|
||||
, a_ids_user
|
||||
, a_get_inactive_user
|
||||
, a_ids_permission
|
||||
, a_ids_access_level
|
||||
, a_ids_product
|
||||
, a_debug
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- Clear previous proc results
|
||||
DROP TABLE IF EXISTS tmp_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Product_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval_Temp;
|
||||
-- DROP TABLE IF EXISTS tmp_Split;
|
||||
|
||||
-- Permanent Table
|
||||
CREATE TEMPORARY TABLE tmp_Calc_User (
|
||||
id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
id_user INT NULL,
|
||||
id_permission_required INT NOT NULL,
|
||||
priority_access_level_required INT NOT NULL,
|
||||
id_product INT NULL,
|
||||
is_super_user BIT NULL,
|
||||
priority_access_level_user INT NULL,
|
||||
can_view BIT,
|
||||
can_edit BIT,
|
||||
can_admin BIT
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Product_Calc_User (
|
||||
-- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL
|
||||
id_product INT NOT NULL
|
||||
, id_access_level_required INT NOT NULL
|
||||
, priority_access_level_required INT NOT NULL
|
||||
-- guid BINARY(36) NOT NULL,
|
||||
-- rank_product 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
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split (
|
||||
substring VARCHAR(4000) NOT NULL
|
||||
, as_int INT NULL
|
||||
);
|
||||
DELETE FROM tmp_Split;
|
||||
|
||||
SET v_has_filter_user = CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END;
|
||||
SET a_ids_permission = REPLACE(a_ids_permission, '|', ',');
|
||||
SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END;
|
||||
SET a_ids_access_level = REPLACE(a_ids_access_level, '|', ',');
|
||||
SET v_has_filter_access_level = CASE WHEN a_ids_access_level = '' THEN 0 ELSE 1 END;
|
||||
/*
|
||||
SET a_ids_permutation = REPLACE(a_ids_permutation, '|', ',');
|
||||
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
|
||||
*/
|
||||
SET a_ids_product = REPLACE(a_ids_product, '|', ',');
|
||||
SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
|
||||
SET v_id_access_level_view = (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1);
|
||||
SET v_priority_access_level_view = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE id_access_level = v_id_access_level_view);
|
||||
SET v_priority_access_level_edit = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1);
|
||||
SET v_priority_access_level_admin = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1);
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT
|
||||
v_priority_access_level_view
|
||||
, v_priority_access_level_edit
|
||||
, v_priority_access_level_admin
|
||||
;
|
||||
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);
|
||||
|
||||
INSERT INTO tmp_Split (
|
||||
substring
|
||||
, as_int
|
||||
)
|
||||
SELECT
|
||||
substring
|
||||
, CONVERT(substring, DECIMAL(10,0)) -- AS as_int
|
||||
FROM Split_Temp
|
||||
WHERE 1=1
|
||||
AND GUID = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_guid );
|
||||
|
||||
# Invalid IDs
|
||||
IF EXISTS (
|
||||
SELECT t_S.substring
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_S.as_int = AL.id_access_level
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(AL.id_access_level)
|
||||
OR AL.active = 0
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive access level IDs: ', GROUP_CONCAT(t_S.substring SEPARATOR ', '))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_S.as_int = AL.id_access_level
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(AL.id_access_level)
|
||||
OR AL.active = 0
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF v_has_filter_access_level THEN
|
||||
SET v_id_access_level := (
|
||||
SELECT AL.id_access_level
|
||||
FROM tmp_Split t_S
|
||||
INNER JOIN partsltd_prod.Shop_Access_Level AL
|
||||
ON t_S.as_int = AL.id_access_level
|
||||
AND AL.active
|
||||
ORDER BY AL.priority ASC
|
||||
LIMIT 1
|
||||
);
|
||||
ELSE
|
||||
SET v_id_access_level = v_id_access_level_view;
|
||||
END IF;
|
||||
SET v_priority_access_level := (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE id_access_level = v_id_access_level LIMIT 1);
|
||||
END IF;
|
||||
|
||||
DELETE FROM tmp_Split;
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF v_has_filter_product THEN
|
||||
CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug);
|
||||
|
||||
INSERT INTO tmp_Split (
|
||||
substring
|
||||
, as_int
|
||||
)
|
||||
SELECT
|
||||
substring
|
||||
, CONVERT(substring, DECIMAL(10,0)) AS as_int
|
||||
FROM Split_Temp
|
||||
WHERE 1=1
|
||||
AND GUID = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_guid );
|
||||
|
||||
# Invalid product IDs
|
||||
IF EXISTS (SELECT * FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product WHERE ISNULL(t_S.as_int) OR ISNULL(P.id_product) OR P.active = 0) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive product IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(P.id_product)
|
||||
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;
|
||||
|
||||
DELETE FROM tmp_Split;
|
||||
|
||||
-- Permission IDs
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF v_has_filter_permission THEN
|
||||
CALL partsltd_prod.p_split(a_guid, a_ids_permission, ',', a_debug);
|
||||
|
||||
INSERT INTO tmp_Split (
|
||||
substring
|
||||
, as_int
|
||||
)
|
||||
SELECT
|
||||
substring
|
||||
, CONVERT(substring, DECIMAL(10,0)) AS as_int
|
||||
FROM Split_Temp
|
||||
WHERE 1=1
|
||||
AND GUID = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_guid );
|
||||
|
||||
# Invalid or inactive
|
||||
IF EXISTS (SELECT PERM.id_permission FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_Permission PERM ON t_S.as_int = PERM.id_permission WHERE ISNULL(t_S.as_int) OR ISNULL(PERM.id_permission) OR PERM.active = 0) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive permission IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Permission PERM ON t_S.as_int = PERM.id_permission
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(PERM.id_permission)
|
||||
OR PERM.active = 0
|
||||
;
|
||||
ELSE
|
||||
SET v_id_permission_required := (
|
||||
SELECT PERM.id_permission
|
||||
FROM partsltd_prod.Shop_Permission PERM
|
||||
INNER JOIN partsltd_prod.Shop_Access_Level AL ON PERM.id_access_level_required = AL.id_access_level
|
||||
ORDER BY AL.priority ASC
|
||||
LIMIT 1
|
||||
);
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
DELETE FROM tmp_Split;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT * FROM tmp_Product_Calc_User;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
-- Invalid user ID
|
||||
CALL partsltd_prod.p_split(a_guid, a_ids_user, ',', a_debug);
|
||||
|
||||
INSERT INTO tmp_Split (
|
||||
substring
|
||||
, as_int
|
||||
)
|
||||
SELECT
|
||||
substring
|
||||
, CONVERT(substring, DECIMAL(10,0)) AS as_int
|
||||
FROM Split_Temp
|
||||
WHERE 1=1
|
||||
AND GUID = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_guid );
|
||||
|
||||
# Invalid or inactive
|
||||
IF EXISTS (SELECT U.id_user FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user WHERE ISNULL(t_S.as_int) OR ISNULL(U.id_user) OR U.active = 0) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive user IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(U.id_user)
|
||||
OR U.active = 0
|
||||
;
|
||||
ELSE
|
||||
/*
|
||||
SET a_ids_user = (
|
||||
SELECT U.id_user
|
||||
FROM tmp_Split t_S
|
||||
INNER JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user
|
||||
);
|
||||
SET v_has_filter_user = ISNULL(a_ids_user);
|
||||
*/
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Split) THEN
|
||||
INSERT INTO tmp_Split (substring, as_int)
|
||||
VALUES ( '', NULL );
|
||||
END IF;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT *
|
||||
FROM tmp_Split;
|
||||
END IF;
|
||||
|
||||
INSERT INTO tmp_Calc_User (
|
||||
id_user
|
||||
, id_permission_required
|
||||
, priority_access_level_required
|
||||
, id_product
|
||||
, priority_access_level_user
|
||||
, is_super_user
|
||||
)
|
||||
SELECT
|
||||
U.id_user
|
||||
, v_id_permission_required
|
||||
, CASE WHEN v_priority_access_level < AL_P.priority THEN v_priority_access_level ELSE AL_P.priority END AS priority_access_level_required
|
||||
, t_P.id_product
|
||||
, CASE WHEN MIN(IFNULL(AL_U.priority, 0)) = 0 THEN v_priority_access_level_view ELSE MIN(IFNULL(AL_U.priority, 0)) END AS priority_access_level_user
|
||||
, IFNULL(U.is_super_user, 0) AS is_super_user
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_User U
|
||||
ON t_S.as_int = U.id_user
|
||||
AND U.active
|
||||
LEFT JOIN partsltd_prod.Shop_User_Role_Link URL
|
||||
ON U.id_user = URL.id_user
|
||||
AND URL.active
|
||||
LEFT JOIN partsltd_prod.Shop_Role_Permission_Link RPL
|
||||
ON URL.id_role = RPL.id_role
|
||||
AND RPL.active
|
||||
LEFT JOIN partsltd_prod.Shop_Access_Level AL_U
|
||||
ON RPL.id_access_level = AL_U.id_access_level
|
||||
AND AL_U.active
|
||||
CROSS JOIN tmp_Product_Calc_User t_P
|
||||
LEFT JOIN partsltd_prod.Shop_Access_Level AL_P
|
||||
ON t_P.id_access_level_required = AL_P.id_access_level
|
||||
AND AL_P.active
|
||||
GROUP BY t_S.as_int, U.id_user, t_P.id_product, AL_P.priority
|
||||
;
|
||||
|
||||
SET v_has_filter_user = EXISTS ( SELECT * FROM tmp_Calc_User LIMIT 1 );
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Calculated fields
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
UPDATE tmp_Calc_User t_U
|
||||
SET
|
||||
t_U.can_view = t_U.is_super_user = 1 OR (t_U.priority_access_level_user <= v_priority_access_level_view AND t_U.priority_access_level_user <= t_U.priority_access_level_required)
|
||||
, t_U.can_edit = t_U.is_super_user = 1 OR (t_U.priority_access_level_user <= v_priority_access_level_edit AND t_U.priority_access_level_user <= t_U.priority_access_level_required)
|
||||
, t_U.can_admin = t_U.is_super_user = 1 OR (t_U.priority_access_level_user <= v_priority_access_level_admin AND t_U.priority_access_level_user <= t_U.priority_access_level_required)
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- Export data to staging table
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
START TRANSACTION;
|
||||
INSERT INTO partsltd_prod.Shop_Calc_User_Temp (
|
||||
guid
|
||||
, id_user
|
||||
, id_permission_required
|
||||
, priority_access_level_required
|
||||
, id_product
|
||||
, is_super_user
|
||||
, priority_access_level_user
|
||||
, can_view
|
||||
, can_edit
|
||||
, can_admin
|
||||
)
|
||||
SELECT
|
||||
a_guid
|
||||
, id_user
|
||||
, id_permission_required
|
||||
, priority_access_level_required
|
||||
, id_product
|
||||
, is_super_user
|
||||
, priority_access_level_user
|
||||
, can_view
|
||||
, can_edit
|
||||
, can_admin
|
||||
FROM tmp_Calc_User
|
||||
;
|
||||
COMMIT;
|
||||
END IF;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT * FROM tmp_Msg_Error;
|
||||
SELECT * FROM tmp_Calc_User;
|
||||
SELECT * FROM tmp_Product_Calc_User;
|
||||
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid;
|
||||
CALL partsltd_prod.p_shop_clear_calc_user ( a_guid, a_debug );
|
||||
END IF;
|
||||
|
||||
-- Clean up
|
||||
DROP TABLE IF EXISTS tmp_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Product_Calc_User;
|
||||
DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval_Temp;
|
||||
-- DROP TABLE IF EXISTS tmp_Split;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
CALL partsltd_prod.p_debug_timing_reporting( v_time_start );
|
||||
END IF;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
/*
|
||||
|
||||
CALL partsltd_prod.p_shop_calc_user (
|
||||
'chips '
|
||||
, NULL
|
||||
, 0
|
||||
, '2'
|
||||
, '1'
|
||||
, '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;
|
||||
|
||||
*/
|
||||
@@ -1,753 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
CALL p_shop_user_eval (
|
||||
UUID(), # a_guid
|
||||
'', # a_ids_user
|
||||
0, # a_get_inactive_users
|
||||
'1', # a_ids_permission
|
||||
'', # a_ids_access_level
|
||||
'1' # a_ids_product
|
||||
)
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`localhost` 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 ;
|
||||
|
||||
*/
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_user_eval;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_user_eval (
|
||||
IN a_guid BINARY(36),
|
||||
IN a_ids_user LONGTEXT,
|
||||
IN a_get_inactive_users BIT,
|
||||
IN a_ids_permission VARCHAR(500),
|
||||
IN a_ids_access_level VARCHAR(100),
|
||||
IN a_ids_product VARCHAR(4000) -- IN a_ids_permutation VARCHAR(4000)
|
||||
)
|
||||
BEGIN
|
||||
-- Variable declaration
|
||||
DECLARE v_has_filter_permission BIT;
|
||||
DECLARE v_has_filter_user BIT;
|
||||
DECLARE v_has_filter_access_level BIT;
|
||||
-- DECLARE v_has_filter_permutation BIT;
|
||||
DECLARE v_has_filter_product BIT;
|
||||
DECLARE v_id_permission_product INT;
|
||||
DECLARE v_id_permission INT;
|
||||
-- DECLARE v_ids_product VARCHAR(500);
|
||||
DECLARE v_id_access_level_view INT;
|
||||
# DECLARE v_id_access_level_product_required INT;
|
||||
DECLARE v_priority_access_level_view INT;
|
||||
DECLARE v_priority_access_level_edit INT;
|
||||
DECLARE v_priority_access_level_admin INT;
|
||||
DECLARE v_id_access_level INT;
|
||||
DECLARE v_priority_access_level INT;
|
||||
DECLARE v_now TIMESTAMP;
|
||||
DECLARE v_ids_row_delete VARCHAR(500);
|
||||
DECLARE v_code_error_data VARCHAR(200);
|
||||
DECLARE v_id_error_data INT;
|
||||
DECLARE v_code_error_permission VARCHAR(200);
|
||||
|
||||
SET v_id_error_data = 1;
|
||||
SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = v_id_error_data);
|
||||
|
||||
SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2);
|
||||
|
||||
-- Clear previous proc results
|
||||
# DROP TABLE IF EXISTS tmp_User_Role_Link;
|
||||
# DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link;
|
||||
DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval;
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
|
||||
|
||||
-- Parse arguments + get default values
|
||||
SET a_guid := IFNULL(a_guid, UUID());
|
||||
SET a_ids_user := TRIM(IFNULL(a_ids_user, ''));
|
||||
SET a_get_inactive_users := IFNULL(a_get_inactive_users, 0);
|
||||
SET a_ids_permission := TRIM(IFNULL(a_ids_permission, ''));
|
||||
SET a_ids_access_level := TRIM(IFNULL(a_ids_access_level, ''));
|
||||
SET a_ids_product := TRIM(IFNULL(a_ids_product, ''));
|
||||
|
||||
-- Permanent Table
|
||||
CREATE TABLE IF NOT EXISTS Shop_User_Eval_Temp (
|
||||
id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
guid BINARY(36) NOT NULL,
|
||||
id_user INT NULL,
|
||||
id_permission_required INT NOT NULL,
|
||||
CONSTRAINT FK_Shop_User_Eval_Temp_id_permission_required
|
||||
FOREIGN KEY (id_permission_required)
|
||||
REFERENCES Shop_Permission (id_permission),
|
||||
/*
|
||||
id_access_level_required INT NOT NULL,
|
||||
CONSTRAINT FK_Shop_User_Eval_Temp_id_access_level_required
|
||||
FOREIGN KEY (id_access_level_required)
|
||||
REFERENCES Shop_Access_Level (id_access_level),
|
||||
*/
|
||||
priority_access_level_required INT NOT NULL,
|
||||
/*
|
||||
CONSTRAINT FK_Shop_User_Eval_Temp_priority_access_level_required
|
||||
FOREIGN KEY (priority_access_level_required)
|
||||
REFERENCES Shop_Access_Level (priority),
|
||||
*/
|
||||
id_product INT NULL,
|
||||
CONSTRAINT FK_Shop_User_Eval_Temp_id_product
|
||||
FOREIGN KEY (id_product)
|
||||
REFERENCES Shop_Product (id_product),
|
||||
/*
|
||||
id_permutation INT NULL,
|
||||
CONSTRAINT FK_Shop_User_Eval_Temp_id_permutation
|
||||
FOREIGN KEY (id_permutation)
|
||||
REFERENCES Shop_Product_Permutation (id_permutation),
|
||||
*/
|
||||
is_super_user BIT NULL,
|
||||
priority_access_level_user INT NULL,
|
||||
/*
|
||||
CONSTRAINT FK_Shop_User_Eval_Temp_priority_access_level_minimum
|
||||
FOREIGN KEY (priority_access_level_minimum)
|
||||
REFERENCES Shop_Access_Level (priority)
|
||||
*/
|
||||
can_view BIT,
|
||||
can_edit BIT,
|
||||
can_admin BIT -- DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Product_p_Shop_User_Eval (
|
||||
id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
id_product INT NOT NULL,
|
||||
id_access_level_required INT NOT NULL,
|
||||
priority_access_level_required INT NOT NULL,
|
||||
guid BINARY(36) NOT NULL,
|
||||
rank_product 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
|
||||
);
|
||||
|
||||
# select * from Shop_Msg_Error_Type;
|
||||
|
||||
-- Parse filters
|
||||
SET a_guid := IFNULL(a_guid, UUID());
|
||||
/*
|
||||
IF a_guid IS NULL OR EXISTS (SELECT * FROM Shop_User_Eval_Temp WHERE a_guid = guid) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
VALUES (
|
||||
a_guid,
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1),
|
||||
v_code_error_data,
|
||||
CONCAT('Invalid guid argument: ', IFNULL(a_guid, 'NULL'))
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
*/
|
||||
SET v_has_filter_user = CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END;
|
||||
SET a_ids_permission = REPLACE(a_ids_permission, '|', ',');
|
||||
SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END;
|
||||
SET a_ids_access_level = REPLACE(a_ids_access_level, '|', ',');
|
||||
SET v_has_filter_access_level = CASE WHEN a_ids_access_level = '' THEN 0 ELSE 1 END;
|
||||
/*
|
||||
SET a_ids_permutation = REPLACE(a_ids_permutation, '|', ',');
|
||||
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
|
||||
*/
|
||||
SET a_ids_product = REPLACE(a_ids_product, '|', ',');
|
||||
SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
|
||||
SET v_id_access_level_view = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1);
|
||||
SET v_priority_access_level_view = (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level_view);
|
||||
SET v_priority_access_level_edit = (SELECT priority FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1);
|
||||
SET v_priority_access_level_admin = (SELECT priority FROM Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1);
|
||||
|
||||
/*
|
||||
select v_priority_access_level_view,
|
||||
v_priority_access_level_edit,
|
||||
v_priority_access_level_admin
|
||||
;
|
||||
*/
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
IF v_has_filter_access_level THEN
|
||||
CALL p_split(a_ids_access_level, ',');
|
||||
|
||||
IF EXISTS (
|
||||
SELECT ST.substring
|
||||
FROM Split_Temp ST
|
||||
LEFT JOIN Shop_Access_Level AL
|
||||
ON ST.substring = AL.id_access_level
|
||||
WHERE
|
||||
ISNULL(AL.id_access_level)
|
||||
OR AL.active = 0
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1),
|
||||
v_code_error_data,
|
||||
CONCAT('Invalid access level IDs: ', GROUP_CONCAT(ST.substring SEPARATOR ', '))
|
||||
FROM Split_Temp ST
|
||||
LEFT JOIN Shop_Access_Level AL ON ST.substring = AL.id_access_level
|
||||
WHERE ISNULL(AL.id_access_level)
|
||||
;
|
||||
ELSE
|
||||
SET v_id_access_level := (
|
||||
SELECT AL.id_access_level
|
||||
FROM Split_Temp ST
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON CONVERT(ST.substring, DECIMAL(10,0)) = AL.id_access_level
|
||||
AND AL.active
|
||||
ORDER BY AL.priority ASC
|
||||
LIMIT 1
|
||||
);
|
||||
END IF;
|
||||
DROP TABLE Split_Temp;
|
||||
|
||||
/*
|
||||
IF 0 = v_id_access_level OR v_id_access_level <=> NULL THEN
|
||||
# SET v_has_filter_access_level = 0;
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
v_code_error_data,
|
||||
CONCAT('Invalid access level IDs: ', GROUP_CONCAT(ST.substring SEPARATOR ', '))
|
||||
FROM Split_Temp ST
|
||||
LEFT JOIN Shop_Access_Level AL ON ST.substring = AL.id_access_level
|
||||
WHERE ISNULL(AL.id_access_level)
|
||||
;
|
||||
END IF;
|
||||
*/
|
||||
/* select * from Shop_Access_Level
|
||||
END IF;
|
||||
IF NOT v_has_filter_access_level THEN
|
||||
*/
|
||||
ELSE
|
||||
SET v_id_access_level = v_id_access_level_view;
|
||||
END IF;
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
/*
|
||||
IF v_has_filter_permutation THEN
|
||||
INSERT INTO tmp_Product_p_Shop_User_Eval (
|
||||
id_product,
|
||||
id_permutation,
|
||||
id_access_level_required,
|
||||
guid,
|
||||
rank_permutation
|
||||
)
|
||||
SELECT
|
||||
PP.id_product,
|
||||
PP.id_permutation,
|
||||
PP.id_access_level_required,
|
||||
a_guid,
|
||||
RANK() OVER (ORDER BY PP.id_product, PP.id_permutation, AL.priority) AS rank_permutation
|
||||
FROM Shop_Product_Permutation PP
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON PP.id_access_level_required = AL.id_access_level
|
||||
AND AL.active
|
||||
WHERE FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0
|
||||
# AND P.active # not worried as we want users to be able to see their order history
|
||||
;
|
||||
/*
|
||||
DELETE FROM tmp_Product_p_Shop_User_Eval
|
||||
WHERE rank_permutation > 1
|
||||
;
|
||||
*
|
||||
SET v_has_filter_permutation = EXISTS (SELECT * FROM tmp_Product_p_Shop_User_Eval WHERE a_guid = guid);
|
||||
END IF;
|
||||
|
||||
IF v_has_filter_permission THEN
|
||||
# Invalid permission IDs
|
||||
IF EXISTS (SELECT id_permission FROM Shop_Permission WHERE FIND_IN_SET(id_permission, a_ids_permission) > 0 AND NOT active) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
VALUES (
|
||||
a_guid,
|
||||
v_code_error_data,
|
||||
CONCAT('The following permissions are no longer active: ', (SELECT GROUP_CONCAT(name SEPARATOR ', ') FROM Shop_Permission WHERE FIND_IN_SET(id_permission, a_ids_permission) > 0 AND NOT active))
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
*/
|
||||
|
||||
IF v_has_filter_product THEN
|
||||
CALL p_split(a_ids_product, ',');
|
||||
|
||||
# Invalid product IDs
|
||||
IF EXISTS (SELECT * FROM Split_Temp ST LEFT JOIN Shop_Product P ON ST.substring = P.id_product WHERE ISNULL(P.id_product)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1),
|
||||
v_code_error_data,
|
||||
CONCAT('Invalid product IDs: ', IFNULL(GROUP_CONCAT(ST.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM Split_Temp ST
|
||||
LEFT JOIN Shop_Product P ON ST.substring = P.id_product
|
||||
WHERE ISNULL(P.id_product)
|
||||
;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
INSERT INTO tmp_Product_p_Shop_User_Eval (
|
||||
id_product,
|
||||
-- id_permutation,
|
||||
id_access_level_required,
|
||||
priority_access_level_required,
|
||||
guid,
|
||||
rank_product -- rank_permutation
|
||||
)
|
||||
SELECT
|
||||
DISTINCT P.id_product,
|
||||
-- PP.id_permutation,
|
||||
P.id_access_level_required,
|
||||
AL.priority AS priority_access_level_required,
|
||||
a_guid,
|
||||
RANK() OVER (ORDER BY C.display_order, P.display_order) AS rank_product
|
||||
FROM Split_Temp ST
|
||||
INNER JOIN Shop_Product P ON ST.substring = P.id_product # Shop_Product_Permutation PP
|
||||
INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON P.id_access_level_required = AL.id_access_level
|
||||
AND AL.active
|
||||
WHERE FIND_IN_SET(P.id_product, a_ids_product) > 0 # FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0
|
||||
# AND P.active # not worried as we want users to be able to see their order history
|
||||
;
|
||||
/*
|
||||
DELETE FROM tmp_Product_p_Shop_User_Eval
|
||||
WHERE rank_permutation > 1
|
||||
;
|
||||
*/
|
||||
|
||||
SET v_has_filter_product = EXISTS (SELECT * FROM tmp_Product_p_Shop_User_Eval WHERE a_guid = guid);
|
||||
|
||||
UPDATE tmp_Product_p_Shop_User_Eval t_P
|
||||
INNER JOIN Shop_Product P ON t_P.id_product = P.id_product
|
||||
INNER JOIN Shop_Product_Category PC ON P.id_category = PC.id_category
|
||||
INNER JOIN 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)
|
||||
;
|
||||
END IF;
|
||||
|
||||
DROP TABLE Split_Temp;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Permission IDs
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
IF v_has_filter_permission THEN
|
||||
CALL p_split(a_ids_permission, ',');
|
||||
|
||||
# Invalid
|
||||
IF EXISTS (SELECT PERM.id_permission FROM Split_Temp ST LEFT JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission WHERE ISNULL(PERM.id_permission)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1),
|
||||
v_code_error_data,
|
||||
CONCAT('Invalid permission IDs: ', IFNULL(GROUP_CONCAT(ST.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM Split_Temp ST
|
||||
LEFT JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission
|
||||
WHERE ISNULL(PERM.id_permission)
|
||||
;
|
||||
END IF;
|
||||
|
||||
# Inactive
|
||||
IF EXISTS (SELECT PERM.id_permission FROM Split_Temp ST INNER JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission WHERE PERM.active = 0) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1),
|
||||
v_code_error_data,
|
||||
CONCAT('The following permissions are not active: ', IFNULL(GROUP_CONCAT(ST.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM Split_Temp ST
|
||||
INNER JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission
|
||||
WHERE PERM.active = 0
|
||||
;
|
||||
END IF;
|
||||
|
||||
DROP TABLE Split_Temp;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Invalid user ID
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
IF v_has_filter_user = 1 THEN
|
||||
/*
|
||||
SET a_ids_user := (SELECT id_user FROM Shop_User WHERE id_user LIKE a_ids_user AND active);
|
||||
SET v_has_filter_user = NOT (a_ids_user <=> NULL);
|
||||
*/
|
||||
IF ISNULL((SELECT id_user FROM Shop_User WHERE id_user LIKE a_ids_user AND active)) THEN -- NOT v_has_filter_user THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
VALUES (
|
||||
a_guid,
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1),
|
||||
v_code_error_data,
|
||||
CONCAT('Invalid user ID: ', IFNULL(a_ids_user, 'NULL'))
|
||||
)
|
||||
;
|
||||
SET a_ids_user = NULL;
|
||||
SET v_has_filter_user = 0;
|
||||
ELSE
|
||||
SET v_has_filter_user = 1;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Get users
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
INSERT INTO Shop_User_Eval_Temp (
|
||||
guid,
|
||||
id_user,
|
||||
id_permission_required,
|
||||
priority_access_level_required
|
||||
/*
|
||||
priority_access_level_user,
|
||||
is_super_user,
|
||||
can_view,
|
||||
can_edit,
|
||||
can_admin
|
||||
*/
|
||||
)
|
||||
SELECT a_guid,
|
||||
U.id_user,
|
||||
P.id_permission,
|
||||
AL.priority
|
||||
FROM Shop_Permission P
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON P.id_access_level_required = AL.id_access_level
|
||||
AND AL.active
|
||||
CROSS JOIN (
|
||||
SELECT id_user
|
||||
FROM Shop_User U
|
||||
WHERE 1=1
|
||||
AND FIND_IN_SET(U.id_user, a_ids_user) > 0
|
||||
AND U.active
|
||||
) U
|
||||
WHERE FIND_IN_SET(P.id_permission, a_ids_permission) > 0
|
||||
;
|
||||
|
||||
/*
|
||||
IF v_has_filter_permutation THEN
|
||||
SET v_ids_row_delete := (SELECT GROUP_CONCAT(id_row SEPARATOR ',') FROM Shop_User_Eval_Temp WHERE a_guid = guid);
|
||||
|
||||
INSERT INTO Shop_User_Eval_Temp (
|
||||
guid,
|
||||
id_user,
|
||||
id_permission_required,
|
||||
id_product,
|
||||
id_permutation,
|
||||
priority_access_level_required
|
||||
)
|
||||
SELECT UE_T.guid,
|
||||
UE_T.id_user,
|
||||
UE_T.id_permission_required,
|
||||
t_P.id_product,
|
||||
t_P.id_permutation,
|
||||
CASE WHEN UE_T.priority_access_level_required < AL.priority THEN UE_T.priority_access_level_required ELSE AL.priority END -- UE_T.priority_access_level_required
|
||||
FROM tmp_Product_p_Shop_User_Eval t_P
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON t_P.id_access_leveL_required = AL.id_access_level
|
||||
AND AL.active
|
||||
CROSS JOIN Shop_User_Eval_Temp UE_T
|
||||
ON a_ids_user = UE_T.id_user
|
||||
WHERE a_guid = t_P.guid
|
||||
;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
WHERE FIND_IN_SET(id_row, v_ids_row_delete) > 0
|
||||
;
|
||||
END IF;
|
||||
*/
|
||||
IF v_has_filter_product THEN
|
||||
SET v_ids_row_delete := (SELECT GROUP_CONCAT(id_row SEPARATOR ',') FROM Shop_User_Eval_Temp WHERE a_guid = guid);
|
||||
|
||||
INSERT INTO Shop_User_Eval_Temp (
|
||||
guid,
|
||||
id_user,
|
||||
id_permission_required,
|
||||
id_product,
|
||||
-- id_permutation,
|
||||
priority_access_level_required
|
||||
)
|
||||
SELECT UE_T.guid,
|
||||
UE_T.id_user,
|
||||
UE_T.id_permission_required,
|
||||
t_P.id_product,
|
||||
-- t_P.id_permutation,
|
||||
CASE WHEN UE_T.priority_access_level_required < AL.priority THEN UE_T.priority_access_level_required ELSE AL.priority END -- UE_T.priority_access_level_required
|
||||
FROM tmp_Product_p_Shop_User_Eval t_P
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON t_P.id_access_leveL_required = AL.id_access_level
|
||||
AND AL.active
|
||||
CROSS JOIN Shop_User_Eval_Temp UE_T
|
||||
ON a_ids_user = UE_T.id_user
|
||||
WHERE a_guid = t_P.guid
|
||||
;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
WHERE FIND_IN_SET(id_row, v_ids_row_delete) > 0
|
||||
;
|
||||
END IF;
|
||||
|
||||
/*
|
||||
INSERT INTO Shop_User_Eval_Temp (
|
||||
guid,
|
||||
id_user,
|
||||
id_permission_required,
|
||||
# id_access_level_required,
|
||||
priority_access_level_required,
|
||||
priority_access_level_user,
|
||||
is_super_user
|
||||
/*
|
||||
can_view,
|
||||
can_edit,
|
||||
can_admin
|
||||
*
|
||||
)
|
||||
SELECT a_guid,
|
||||
U.id_user,
|
||||
P.id_permission,
|
||||
AL.priority,
|
||||
/*
|
||||
v_id_permission,
|
||||
v_id_access_level,
|
||||
*
|
||||
MIN(AL.priority),
|
||||
U.is_super_user
|
||||
/*
|
||||
CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_view THEN 1 ELSE 0 END END,
|
||||
CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_edit THEN 1 ELSE 0 END END,
|
||||
CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_admin THEN 1 ELSE 0 END END
|
||||
*
|
||||
FROM Shop_User U
|
||||
INNER JOIN Shop_User_Role_Link URL
|
||||
ON U.id_user = URL.id_user
|
||||
AND URL.active
|
||||
INNER JOIN Shop_Role_Permission_Link RPL
|
||||
ON URL.id_role = RPL.id_role
|
||||
AND RPL.active
|
||||
INNER JOIN Shop_Permission P
|
||||
ON RPL.id_permission = P.id_permission
|
||||
AND P.active
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON RPL.id_access_level = AL.id_access_level
|
||||
AND AL.active
|
||||
WHERE U.id_user = a_ids_user
|
||||
AND (a_get_inactive_users OR U.active)
|
||||
AND FIND_IN_SET(P.id_permission, a_ids_permission) > 0
|
||||
# AND v_id_permission = P.id_permission
|
||||
# AND v_id_access_level = AL.id_access_leveld
|
||||
GROUP BY U.id_user, P.id_permission # , is_super_user
|
||||
;
|
||||
*/
|
||||
|
||||
IF v_has_filter_user THEN
|
||||
UPDATE Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_User U
|
||||
ON UE_T.id_user = U.id_user
|
||||
AND U.active
|
||||
INNER JOIN Shop_User_Role_Link URL
|
||||
ON U.id_user = URL.id_user
|
||||
AND URL.active
|
||||
INNER JOIN Shop_Role_Permission_Link RPL
|
||||
ON URL.id_role = RPL.id_role
|
||||
AND RPL.active
|
||||
INNER JOIN Shop_Access_Level AL
|
||||
ON RPL.id_access_level = AL.id_access_level
|
||||
AND AL.active
|
||||
SET UE_T.priority_access_level_user = AL.priority,
|
||||
UE_T.is_super_user = U.is_super_user,
|
||||
UE_T.can_view = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN ISNULL(AL.priority) THEN 1 ELSE CASE WHEN AL.priority <= v_priority_access_level_view AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END END,
|
||||
UE_T.can_edit = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_edit AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END,
|
||||
UE_T.can_admin = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_admin AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END
|
||||
WHERE UE_T.guid = a_guid
|
||||
AND UE_T.id_user = a_ids_user
|
||||
AND RPL.id_permission = UE_T.id_permission_required
|
||||
# GROUP BY UE_T.id_user
|
||||
;
|
||||
ELSE
|
||||
UPDATE Shop_User_Eval_Temp UE_T
|
||||
SET UE_T.priority_access_level_user = v_priority_access_level_view,
|
||||
UE_T.is_super_user = 0,
|
||||
UE_T.can_view = (v_priority_access_level_view <= UE_T.priority_access_level_required),
|
||||
UE_T.can_edit = 0,
|
||||
UE_T.can_admin = 0
|
||||
WHERE UE_T.guid = a_guid
|
||||
AND UE_T.id_user = a_ids_user
|
||||
# GROUP BY UE_T.id_user
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN
|
||||
SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid;
|
||||
END IF;
|
||||
|
||||
-- select * from tmp_Product_p_Shop_User_Eval;
|
||||
-- Clean up
|
||||
DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval;
|
||||
# DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link;
|
||||
# DROP TABLE IF EXISTS tmp_Msg_Error;
|
||||
DROP TABLE IF EXISTS Split_Temp;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
CALL p_shop_user_eval ('00550ef3-2bfa-11ef-b83e-b42e9986184a', NULL, 0, '2', '1', '1,2,3,4,5');
|
||||
SELECT *
|
||||
FROM Shop_User_Eval_Temp
|
||||
;
|
||||
|
||||
DROP TABLE Shop_User_Eval_Temp;
|
||||
select CURRENT_USER();
|
||||
CALL p_shop_user_eval('nips', 'auth0|6582b95c895d09a70ba10fef', 0, '5', '2', '1');
|
||||
SELECT *
|
||||
FROM Shop_User_Eval_Temp
|
||||
;
|
||||
DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
DROP TABLE IF EXISTS tmp_Msg_Error;
|
||||
select * from tmp_Msg_Error;
|
||||
select * from shop_product;
|
||||
|
||||
CALL p_shop_user_eval (
|
||||
-- '00550ef3-2bfa-11ef-b83e-b42e9986184a', NULL, 0, '2', '1', '1,2,3,4,5,6');
|
||||
'56c9dfc1-e22f-11ee-aab4-b42e9986184a', # a_guid
|
||||
'', # a_ids_user # 'auth0|6582b95c895d09a70ba10fef',
|
||||
false, # a_get_inactive_users
|
||||
'4,5', # a_ids_permission
|
||||
'1', # a_ids_access_level
|
||||
-- null, # a_ids_product
|
||||
'1,2,3' # a_ids_permutation
|
||||
);
|
||||
|
||||
SELECT *
|
||||
FROM Shop_User_Eval_Temp
|
||||
;
|
||||
|
||||
DROP TABLE Shop_User_Eval_Temp;
|
||||
|
||||
|
||||
SELECT *
|
||||
FROM Shop_Permission
|
||||
;
|
||||
|
||||
SELECT *
|
||||
FROM Shop_Access_Level
|
||||
;
|
||||
|
||||
SELECT *
|
||||
FROM Shop_Product
|
||||
;
|
||||
|
||||
SELECT *
|
||||
FROM Shop_Product_Permutation
|
||||
;
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
SELECT 'NOODS' AS guid,
|
||||
U.id_user AS id_user,
|
||||
P.id_permission AS id_permission_required,
|
||||
AL.id_access_level AS id_access_level_required,
|
||||
/*
|
||||
v_id_permission,
|
||||
v_id_access_level,
|
||||
*
|
||||
AL.priority, # MIN(AL.priority),
|
||||
U.is_super_user
|
||||
/*
|
||||
CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_view THEN 1 ELSE 0 END END,
|
||||
CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_edit THEN 1 ELSE 0 END END,
|
||||
CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_admin THEN 1 ELSE 0 END END
|
||||
*
|
||||
FROM Shop_User U
|
||||
INNER JOIN Shop_User_Role_Link URL
|
||||
ON U.id_user = URL.id_user
|
||||
AND URL.active
|
||||
INNER JOIN Shop_Role_Permission_Link RPL
|
||||
ON URL.id_role = RPL.id_role
|
||||
AND RPL.active
|
||||
INNER JOIN Shop_Permission P
|
||||
ON RPL.id_permission = P.id_permission
|
||||
AND P.active
|
||||
inner JOIN Shop_Access_Level AL
|
||||
# ON P.id_access_level_required = AL.id_access_level
|
||||
ON RPL.id_access_level = AL.id_access_level
|
||||
AND AL.active
|
||||
WHERE U.id_user = 'auth0|6582b95c895d09a70ba10fef'
|
||||
AND U.active
|
||||
AND FIND_IN_SET(P.id_permission, '1,2') > 0
|
||||
# AND v_id_access_level = AL.id_access_leveld
|
||||
# GROUP BY U.id_user, P.id_permission, AL.id_access_level # , is_super_user
|
||||
|
||||
*/
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
-- 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;
|
||||
|
||||
*/
|
||||
45
static/MySQL/6501_p_shop_clear_calc_user.sql
Normal file
45
static/MySQL/6501_p_shop_clear_calc_user.sql
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_clear_Shop_Calc_User_Temp;
|
||||
DROP PROCEDURE IF EXISTS p_clear_Shop_Calc_User_Temp;
|
||||
DROP PROCEDURE IF EXISTS p_shop_clear_calc_user;
|
||||
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_clear_calc_user (
|
||||
IN a_guid BINARY(36)
|
||||
, IN a_debug BIT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE v_time_start TIMESTAMP(6);
|
||||
SET v_time_start := CURRENT_TIMESTAMP(6);
|
||||
|
||||
CALL p_validate_guid ( a_guid );
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid
|
||||
;
|
||||
|
||||
COMMIT;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
CALL partsltd_prod.p_debug_timing_reporting( v_time_start );
|
||||
END IF;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
/*
|
||||
|
||||
CALL p_shop_clear_calc_user (
|
||||
'noods, cheese ' # a_guid
|
||||
, 1 -- debug
|
||||
);
|
||||
|
||||
SELECT *
|
||||
FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = 'noods, cheese '
|
||||
;
|
||||
|
||||
*/
|
||||
@@ -25,9 +25,9 @@ BEGIN
|
||||
AL.id_access_level
|
||||
, AL.code
|
||||
, AL.name
|
||||
, AL.active
|
||||
, AL.priority
|
||||
, AL.display_order
|
||||
, AL.active
|
||||
FROM Shop_Access_Level AL
|
||||
WHERE
|
||||
a_get_inactive_access_level = 1
|
||||
|
||||
@@ -185,11 +185,11 @@ BEGIN
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
|
||||
|
||||
CALL p_shop_user_eval(a_guid, a_id_user, FALSE, v_id_permission_product, v_id_access_level_edit, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(a_guid, a_id_user, FALSE, v_id_permission_product, v_id_access_level_edit, v_ids_product_permission);
|
||||
|
||||
UPDATE tmp_Category t_C
|
||||
INNER JOIN Shop_Product P ON t_C.id_category = P.id_product
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON P.id_product = UE_T.id_product
|
||||
AND UE_T.GUID = a_guid
|
||||
SET
|
||||
@@ -198,7 +198,7 @@ BEGIN
|
||||
, t_C.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_clear_shop_user_eval_temp(a_guid);
|
||||
CALL p_shop_clear_calc_user(a_guid);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
@@ -179,11 +179,11 @@ BEGIN
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
|
||||
|
||||
CALL p_shop_user_eval(a_guid, a_id_user, v_id_permission_product, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(a_guid, a_id_user, v_id_permission_product, v_ids_product_permission);
|
||||
|
||||
UPDATE tmp_Category t_C
|
||||
INNER JOIN Shop_Product P ON t_C.id_category = P.id_product
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON P.id_product = UE_T.id_product
|
||||
AND UE_T.GUID = a_guid
|
||||
SET
|
||||
@@ -192,7 +192,7 @@ BEGIN
|
||||
, t_C.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_shop_user_eval_clear_temp(a_guid);
|
||||
CALL p_shop_calc_user_clear_temp(a_guid);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
530
static/MySQL/7201_p_shop_calc_product_permutation.sql
Normal file
530
static/MySQL/7201_p_shop_calc_product_permutation.sql
Normal file
@@ -0,0 +1,530 @@
|
||||
-- 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'
|
||||
;
|
||||
*/
|
||||
578
static/MySQL/7201_p_shop_get_many_product.sql
Normal file
578
static/MySQL/7201_p_shop_get_many_product.sql
Normal file
@@ -0,0 +1,578 @@
|
||||
-- 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;
|
||||
*/
|
||||
52
static/MySQL/7202_p_shop_clear_calc_product_permutation.sql
Normal file
52
static/MySQL/7202_p_shop_clear_calc_product_permutation.sql
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation;
|
||||
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_clear_calc_product_permutation (
|
||||
IN a_guid BINARY(36)
|
||||
)
|
||||
BEGIN
|
||||
IF ISNULL(a_guid) THEN
|
||||
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'GUID is required.';
|
||||
|
||||
ELSE
|
||||
|
||||
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;
|
||||
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
/*
|
||||
|
||||
CALL p_shop_clear_calc_product_permutation (
|
||||
'noods, cheese ' # a_guid
|
||||
);
|
||||
|
||||
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
|
||||
;
|
||||
|
||||
*/
|
||||
@@ -170,10 +170,10 @@ BEGIN
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
|
||||
|
||||
CALL p_shop_user_eval(a_guid, a_id_user, v_id_permission_product, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(a_guid, a_id_user, v_id_permission_product, v_ids_product_permission);
|
||||
|
||||
UPDATE tmp_Product t_P
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON t_P.id_product = UE_T.id_product
|
||||
AND UE_T.GUID = a_guid
|
||||
SET
|
||||
@@ -182,7 +182,7 @@ BEGIN
|
||||
, t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_shop_user_eval_clear_temp(a_guid);
|
||||
CALL p_shop_calc_user_clear_temp(a_guid);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
686
static/MySQL/7204_p_shop_calc_product_permutation.sql
Normal file
686
static/MySQL/7204_p_shop_calc_product_permutation.sql
Normal file
@@ -0,0 +1,686 @@
|
||||
-- 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 partsltd_prod.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_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 partsltd_prod.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 partsltd_prod.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_Split;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Category_calc;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Product_calc;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_calc;
|
||||
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Category_calc (
|
||||
id_category INT NOT NULL
|
||||
-- , active BIT NOT NULL
|
||||
-- display_order INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Product_calc (
|
||||
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_calc (
|
||||
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
|
||||
);
|
||||
|
||||
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_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;
|
||||
|
||||
CALL p_validate_guid ( a_guid );
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT
|
||||
v_has_filter_product_category
|
||||
, v_has_filter_product
|
||||
, v_has_filter_permutation
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- Categories
|
||||
IF TRUE THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
CALL partsltd_prod.p_split(a_guid, a_ids_product_category, ',', a_debug);
|
||||
|
||||
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 = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_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_Category PC ON t_S.as_int = PC.id_category
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(PC.id_category)
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive category IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(PC.id_category)
|
||||
-- OR PC.active = 0
|
||||
;
|
||||
ELSE
|
||||
INSERT INTO tmp_Category_calc (
|
||||
id_category
|
||||
)
|
||||
SELECT
|
||||
PC.id_category
|
||||
FROM tmp_Split t_S
|
||||
RIGHT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category
|
||||
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
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Products
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug);
|
||||
|
||||
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 = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_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 P ON t_S.as_int = P.id_product
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(P.id_product)
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive product IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(P.id_product)
|
||||
-- OR PC.active = 0
|
||||
;
|
||||
ELSE
|
||||
INSERT INTO tmp_Product_calc (
|
||||
id_category
|
||||
, id_product
|
||||
)
|
||||
SELECT
|
||||
P.id_category
|
||||
, P.id_product
|
||||
FROM tmp_Split t_S
|
||||
RIGHT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product
|
||||
INNER JOIN tmp_Category_calc 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
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Permutations
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug);
|
||||
|
||||
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 = a_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( a_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_Permutation PP ON t_S.as_int = PP.id_permutation
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(PP.id_permutation)
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
-- guid,
|
||||
id_type,
|
||||
code,
|
||||
msg
|
||||
)
|
||||
SELECT
|
||||
-- a_guid,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_type_error_bad_data,
|
||||
CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(PP.id_permutation)
|
||||
-- OR PC.active = 0
|
||||
;
|
||||
ELSE
|
||||
INSERT INTO tmp_Permutation_calc (
|
||||
id_permutation
|
||||
-- id_category,
|
||||
, id_product
|
||||
)
|
||||
SELECT
|
||||
PP.id_permutation
|
||||
-- P.id_category,
|
||||
, PP.id_product
|
||||
FROM tmp_Split t_S
|
||||
RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation
|
||||
INNER JOIN tmp_Product_calc 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
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
IF EXISTS (SELECT * FROM tmp_Product_calc LIMIT 1) THEN
|
||||
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_Product_calc 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 -- a_get_inactive_user
|
||||
, v_id_permission_product -- a_ids_permission
|
||||
, v_id_access_level_view -- a_ids_access_level
|
||||
, v_ids_product_permission -- a_ids_permutation
|
||||
, false -- a_debug
|
||||
);
|
||||
|
||||
|
||||
UPDATE tmp_Product_calc t_P
|
||||
INNER JOIN partsltd_prod.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 partsltd_prod.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_calc t_P
|
||||
WHERE ISNULL(t_P.can_view)
|
||||
);
|
||||
SET v_ids_category_invalid := (
|
||||
SELECT GROUP_CONCAT(t_P.id_category SEPARATOR ',')
|
||||
FROM (SELECT DISTINCT id_category, id_product, can_view FROM tmp_Product_calc) t_P
|
||||
WHERE ISNULL(t_P.can_view)
|
||||
);
|
||||
|
||||
DELETE
|
||||
FROM tmp_Category_calc t_C
|
||||
WHERE FIND_IN_SET(t_C.id_category, v_ids_category_invalid) > 0
|
||||
;
|
||||
|
||||
DELETE
|
||||
FROM tmp_Product_calc t_P
|
||||
WHERE FIND_IN_SET(t_P.id_product, v_ids_product_invalid) > 0
|
||||
;
|
||||
|
||||
DELETE
|
||||
FROM tmp_Permutation_calc t_PP
|
||||
WHERE FIND_IN_SET(t_PP.id_product, v_ids_product_invalid) > 0
|
||||
;
|
||||
|
||||
CALL p_shop_clear_calc_user( a_guid, a_debug );
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT * FROM tmp_Category_calc;
|
||||
SELECT * FROM tmp_Product_calc;
|
||||
SELECT * FROM tmp_Permutation_calc;
|
||||
END IF;
|
||||
|
||||
-- Transaction
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
/*
|
||||
DELETE FROM tmp_Category_calc;
|
||||
DELETE FROM tmp_Product_calc;
|
||||
DELETE FROM tmp_Permutation_calc;
|
||||
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_calc t_C
|
||||
INNER JOIN partsltd_prod.Shop_Product_Category PC ON t_C.id_category = PC.id_category
|
||||
LEFT JOIN tmp_Product_calc 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_calc t_P
|
||||
INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product
|
||||
INNER JOIN tmp_Category_calc t_C ON t_P.id_category = t_C.id_category
|
||||
INNER JOIN partsltd_prod.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_calc t_PP
|
||||
INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation
|
||||
INNER JOIN tmp_Product_calc t_P ON t_PP.id_product = t_P.id_product
|
||||
INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product
|
||||
INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category
|
||||
LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation
|
||||
LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement
|
||||
LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement
|
||||
LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement
|
||||
INNER JOIN partsltd_prod.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 partsltd_prod.Shop_Msg_Error_Type MET
|
||||
ON t_ME.id_type = MET.id_type
|
||||
WHERE guid = a_guid
|
||||
;
|
||||
*/
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT *
|
||||
FROM tmp_Msg_Error
|
||||
;
|
||||
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Category_Temp
|
||||
WHERE GUID = a_guid
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Temp
|
||||
WHERE GUID = a_guid
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Permutation_Temp
|
||||
WHERE GUID = a_guid
|
||||
;
|
||||
|
||||
CALL p_shop_clear_calc_product_permutation ( a_guid );
|
||||
END IF;
|
||||
|
||||
-- Clean up
|
||||
-- DROP TEMPORARY TABLE IF EXISTS tmp_Split;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_calc;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Product_calc;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Category_calc;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
|
||||
END IF;
|
||||
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
|
||||
, 0 # a_debug
|
||||
);
|
||||
|
||||
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Category_Temp
|
||||
WHERE GUID = 'NIPS '
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Temp
|
||||
WHERE GUID = 'NIPS '
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Permutation_Temp
|
||||
WHERE GUID = 'NIPS '
|
||||
;
|
||||
|
||||
CALL p_shop_clear_calc_product_permutation ( 'NIPS ' );
|
||||
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Category_Temp
|
||||
WHERE GUID = 'NIPS '
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Temp
|
||||
WHERE GUID = 'NIPS '
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Permutation_Temp
|
||||
WHERE GUID = 'NIPS '
|
||||
;
|
||||
|
||||
*/
|
||||
@@ -1,4 +1,5 @@
|
||||
-- USE partsltd_prod;
|
||||
--
|
||||
USE partsltd_prod;
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_get_many_product;
|
||||
@@ -19,8 +20,10 @@ CREATE PROCEDURE p_shop_get_many_product (
|
||||
, IN a_get_inactive_image BIT
|
||||
, IN a_ids_image VARCHAR(4000)
|
||||
, IN a_get_products_quantity_stock_below_min BIT
|
||||
, IN a_debug BIT
|
||||
)
|
||||
BEGIN
|
||||
|
||||
-- Argument redeclaration
|
||||
-- Variable declaration
|
||||
DECLARE v_has_filter_product_category BIT;
|
||||
@@ -37,13 +40,15 @@ BEGIN
|
||||
-- DECLARE v_now TIMESTAMP;
|
||||
DECLARE v_id_minimum INT;
|
||||
DECLARE v_ids_product_invalid VARCHAR(4000);
|
||||
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');
|
||||
SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW');
|
||||
|
||||
|
||||
-- Argument validation + default values
|
||||
SET a_id_user := TRIM(IFNULL(a_id_user, ''));
|
||||
SET a_id_user := 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, ''));
|
||||
@@ -57,70 +62,84 @@ BEGIN
|
||||
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);
|
||||
SET a_debug := IFNULL(a_debug, 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
|
||||
;
|
||||
*/
|
||||
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_all_image, a_get_inactive_image, a_ids_image
|
||||
, a_get_products_quantity_stock_below_min
|
||||
, a_debug
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- Temporary tables
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Split;
|
||||
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_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
|
||||
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,
|
||||
id_category INT NOT NULL
|
||||
, id_product INT NOT NULL
|
||||
, display_order INT NOT NULL
|
||||
/*
|
||||
active BIT NOT NULL,
|
||||
display_order INT NOT NULL,
|
||||
can_view BIT,
|
||||
can_edit BIT,
|
||||
can_admin BIT
|
||||
*/
|
||||
, 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
|
||||
-- , active BIT NOT NULL
|
||||
-- , display_order INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Image (
|
||||
id_image INT NOT NULL,
|
||||
id_image INT NOT NULL
|
||||
-- id_product INT NOT NULL,
|
||||
id_permutation INT NULL,
|
||||
active BIT 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,
|
||||
-- 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
|
||||
-- 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;
|
||||
@@ -128,195 +147,146 @@ BEGIN
|
||||
|
||||
-- select v_has_filter_product, v_has_filter_permutation;
|
||||
|
||||
CALL partsltd_prod.p_shop_calc_product_permutation (
|
||||
a_id_user
|
||||
, a_get_all_product_category
|
||||
, a_get_inactive_product_category
|
||||
, a_ids_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
|
||||
, v_guid -- a_guid
|
||||
, 0 -- a_debug
|
||||
);
|
||||
|
||||
INSERT INTO tmp_Category (
|
||||
id_category,
|
||||
id_category
|
||||
/*
|
||||
active,
|
||||
display_order
|
||||
*/
|
||||
, display_order
|
||||
)
|
||||
SELECT
|
||||
PC.id_category,
|
||||
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
|
||||
)
|
||||
*/
|
||||
, 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_category,
|
||||
id_product,
|
||||
active,
|
||||
display_order
|
||||
id_product
|
||||
, id_category
|
||||
/*
|
||||
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
|
||||
)
|
||||
P.id_product
|
||||
, P.id_category
|
||||
-- P.active,
|
||||
, 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_category,
|
||||
, id_product
|
||||
, active
|
||||
-- , active
|
||||
-- , display_order
|
||||
)
|
||||
SELECT
|
||||
PP.id_permutation
|
||||
-- P.id_category,
|
||||
, PP.id_product
|
||||
, PP.active
|
||||
-- , 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
|
||||
)
|
||||
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 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
|
||||
IF 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 (
|
||||
substring
|
||||
, as_int
|
||||
)
|
||||
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_User_Eval_Temp;
|
||||
|
||||
CALL p_shop_user_eval(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
|
||||
UPDATE tmp_Product t_P
|
||||
INNER JOIN Shop_User_Eval_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
|
||||
substring
|
||||
, CONVERT(substring, DECIMAL(10,0)) AS as_int
|
||||
FROM Split_Temp
|
||||
WHERE 1=1
|
||||
AND GUID = v_guid
|
||||
AND NOT ISNULL(substring)
|
||||
AND substring != ''
|
||||
;
|
||||
-- select * from Shop_User_Eval_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_clear_shop_user_eval_temp(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
/*
|
||||
DELETE FROM Shop_User_Eval_Temp UE_T
|
||||
WHERE UE_T.GUID = v_guid
|
||||
;
|
||||
*/
|
||||
END IF;
|
||||
|
||||
CALL partsltd_prod.p_clear_split_temp( v_guid );
|
||||
END IF;
|
||||
|
||||
-- select * from tmp_Product;
|
||||
|
||||
-- Returns
|
||||
-- SET v_now := NOW();
|
||||
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_Image I ON t_S.as_int = I.id_image
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(I.id_image)
|
||||
) 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 image IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
|
||||
FROM tmp_Split t_S
|
||||
LEFT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image
|
||||
WHERE
|
||||
ISNULL(t_S.as_int)
|
||||
OR ISNULL(I.id_image)
|
||||
-- OR PC.active = 0
|
||||
;
|
||||
ELSE
|
||||
INSERT INTO tmp_Image (
|
||||
id_image
|
||||
, id_permutation
|
||||
)
|
||||
SELECT
|
||||
I.id_image
|
||||
, I.id_permutation
|
||||
FROM tmp_Split t_S
|
||||
RIGHT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image
|
||||
INNER JOIN tmp_Permutation t_PP ON I.id_permutation = t_PP.id_permutation
|
||||
WHERE
|
||||
(
|
||||
a_get_all_image = 1
|
||||
OR NOT ISNULL(t_S.as_int)
|
||||
)
|
||||
AND (
|
||||
a_get_inactive_image = 1
|
||||
OR I.active = 1
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Outputs
|
||||
# Categories
|
||||
SELECT
|
||||
-- DISTINCT
|
||||
@@ -332,9 +302,9 @@ BEGIN
|
||||
, 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
|
||||
INNER JOIN partsltd_prod.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
|
||||
INNER JOIN partsltd_prod.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
|
||||
;
|
||||
@@ -353,9 +323,9 @@ BEGIN
|
||||
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 partsltd_prod.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
|
||||
INNER JOIN partsltd_prod.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
|
||||
;
|
||||
@@ -370,7 +340,7 @@ BEGIN
|
||||
PP.id_currency_cost,
|
||||
C.code AS code_currency_cost,
|
||||
C.symbol AS symbol_currency_cost,
|
||||
-- PP.profit_local_min,
|
||||
PP.profit_local_min,
|
||||
PP.latency_manufacture_days,
|
||||
PP.id_unit_measurement_quantity,
|
||||
UM_Q.symbol AS symbol_unit_measurement_quantity,
|
||||
@@ -403,15 +373,15 @@ BEGIN
|
||||
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 partsltd_prod.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
|
||||
INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product
|
||||
INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category
|
||||
LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation
|
||||
LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement
|
||||
LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement
|
||||
LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement
|
||||
INNER JOIN partsltd_prod.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
|
||||
;
|
||||
@@ -432,36 +402,17 @@ BEGIN
|
||||
, 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
|
||||
FROM partsltd_prod.Shop_Variation V
|
||||
INNER JOIN partsltd_prod.Shop_Variation_Type VT ON V.id_type = VT.id_type
|
||||
INNER JOIN partsltd_prod.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
|
||||
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,
|
||||
@@ -472,7 +423,7 @@ BEGIN
|
||||
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 partsltd_prod.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
|
||||
@@ -480,7 +431,8 @@ BEGIN
|
||||
;
|
||||
|
||||
# Errors
|
||||
SELECT
|
||||
SELECT *
|
||||
/*
|
||||
t_ME.display_order,
|
||||
t_ME.guid,
|
||||
t_ME.id_type,
|
||||
@@ -488,46 +440,29 @@ BEGIN
|
||||
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 partsltd_prod.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
|
||||
;
|
||||
*/
|
||||
CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid );
|
||||
|
||||
# select 'other outputs';
|
||||
# select * from tmp_Product;
|
||||
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_Image;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Split;
|
||||
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
|
||||
@@ -544,23 +479,25 @@ CALL partsltd_prod.p_shop_get_many_product (
|
||||
, 0 # a_get_inactive_image
|
||||
, '' # a_ids_image
|
||||
, 0 # a_get_products_quantity_stock_below_minimum
|
||||
, 0 # a_debug
|
||||
);
|
||||
|
||||
select * FROM Shop_User_Eval_Temp;
|
||||
/*
|
||||
select * FROM partsltd_prod.Shop_Calc_User_Temp;
|
||||
|
||||
select * from Shop_Product_Category;
|
||||
select * from Shop_Product_Permutation;
|
||||
select * from shop_product_change_set;
|
||||
select * FROM partsltd_prod.Shop_Product_Category;
|
||||
select * FROM partsltd_prod.Shop_Product_Permutation;
|
||||
select * FROM partsltd_prod.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)
|
||||
id_change_set = (select id_change_set FROM partsltd_prod.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 partsltd_prod.Shop_image;
|
||||
select * FROM partsltd_prod.Shop_product;
|
||||
select * from TMP_MSG_ERROR;
|
||||
DROP TABLE TMP_MSG_ERROR;
|
||||
|
||||
@@ -568,11 +505,11 @@ 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
|
||||
|
||||
select * FROM Shop_User_Eval_Temp;
|
||||
select * FROM partsltd_prod.Shop_Calc_User_Temp;
|
||||
select distinct guid
|
||||
-- DELETE
|
||||
FROM Shop_User_Eval_Temp;
|
||||
FROM partsltd_prod.Shop_Calc_User_Temp;
|
||||
*/
|
||||
|
||||
@@ -189,7 +189,7 @@ BEGIN
|
||||
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_shop_user_eval (
|
||||
CALL p_shop_calc_user (
|
||||
v_guid, # a_guid
|
||||
a_id_user, # a_id_user
|
||||
0, # a_get_inactive_users
|
||||
@@ -199,7 +199,7 @@ BEGIN
|
||||
(SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') From tmp_Shop_Product) # a_ids_permutation -- WHERE NOT ISNULL(id_permutation)
|
||||
);
|
||||
|
||||
IF EXISTS (SELECT can_admin FROM Shop_User_Eval_Temp WHERE guid = v_guid AND NOT can_admin) THEN
|
||||
IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
code,
|
||||
@@ -213,7 +213,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE guid = v_guid
|
||||
;
|
||||
END IF;
|
||||
@@ -294,7 +294,7 @@ CALL p_shop_get_many_stripe_product_new (
|
||||
select * from shop_product;
|
||||
select * from shop_product_permutation_variation_link;
|
||||
|
||||
CALL p_shop_user_eval (
|
||||
CALL p_shop_calc_user (
|
||||
'ead789a1-c7ac-11ee-a256-b42e9986184a', # a_guid
|
||||
'auth0|6582b95c895d09a70ba10fef', # a_id_user
|
||||
0, # a_get_inactive_users
|
||||
|
||||
605
static/MySQL/7206_p_shop_save_permutation.sql
Normal file
605
static/MySQL/7206_p_shop_save_permutation.sql
Normal file
@@ -0,0 +1,605 @@
|
||||
|
||||
|
||||
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_save_permutation;
|
||||
|
||||
DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link;
|
||||
DROP TABLE IF EXISTS tmp_Msg_Error;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_save_permutation (
|
||||
IN a_guid VARCHAR(500),
|
||||
IN a_id_user INT,
|
||||
IN a_id_order INT,
|
||||
-- IN a_id_supplier_ordered INT,
|
||||
IN a_id_currency_cost INT,
|
||||
IN a_active BIT,
|
||||
IN a_comment VARCHAR(500)
|
||||
)
|
||||
BEGIN
|
||||
DECLARE v_id_error_type_bad_data INT;
|
||||
DECLARE v_code_error_type_bad_data VARCHAR(50);
|
||||
DECLARE v_id_error_type_no_permission INT;
|
||||
DECLARE v_code_error_type_no_permission VARCHAR(50);
|
||||
DECLARE v_guid_permission BINARY(36);
|
||||
-- DECLARE v_id_user VARCHAR(100);
|
||||
DECLARE v_id_permission_manufacturing_purchase_order INT;
|
||||
DECLARE v_id_access_level_EDIT INT;
|
||||
DECLARE v_ids_product VARCHAR(4000);
|
||||
DECLARE v_ids_product_no_permission VARCHAR(4000);
|
||||
-- DECLARE v_id_order_new INT;
|
||||
DECLARE v_id_change_set INT;
|
||||
DECLARE v_is_new_manufacturing_purchase_order BIT;
|
||||
|
||||
SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY');
|
||||
|
||||
SET v_code_error_type_bad_data = 'BAD_DATA';
|
||||
SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1);
|
||||
SET v_code_error_type_no_permission = 'NO_PERMISSION';
|
||||
SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1);
|
||||
SET v_guid_permission = UUID();
|
||||
-- SET v_id_user = CURRENT_USER();
|
||||
SET v_id_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_MANUFACTURING_PURCHASE_ORDER' LIMIT 1);
|
||||
SET v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT');
|
||||
|
||||
-- Argument default values
|
||||
IF a_guid IS NULL THEN
|
||||
SET a_guid = UUID();
|
||||
END IF;
|
||||
IF a_active IS NULL THEN
|
||||
SET a_active = 0;
|
||||
END IF;
|
||||
|
||||
-- Temporary tables
|
||||
/*
|
||||
CREATE TABLE tmp_Shop_Supplier_Purchase_Order (
|
||||
id_order INT NOT NULL PRIMARY KEY,
|
||||
id_supplier_ordered INT NOT NULL,
|
||||
CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered
|
||||
FOREIGN KEY (id_supplier_ordered)
|
||||
REFERENCES Shop_Supplier(id_supplier),
|
||||
cost_total_local FLOAT NOT NULL,
|
||||
id_currency_cost INT NOT NULL
|
||||
);
|
||||
*/
|
||||
|
||||
CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link (
|
||||
id_link INT NOT NULL PRIMARY KEY,
|
||||
id_order INT NOT NULL,
|
||||
/*
|
||||
CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order
|
||||
FOREIGN KEY (id_order)
|
||||
REFERENCES Shop_Manufacturing_Purchase_Order(id_order),
|
||||
*/
|
||||
id_permutation INT NOT NULL,
|
||||
CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_permutation
|
||||
FOREIGN KEY (id_permutation)
|
||||
REFERENCES Shop_Product_Permutation(id_permutation),
|
||||
cost_total_local FLOAT NOT NULL,
|
||||
id_currency_cost INT NOT NULL,
|
||||
value_produced_total_local FLOAT NOT NULL,
|
||||
quantity_used FLOAT NOT NULL,
|
||||
id_unit_quantity INT NOT NULL,
|
||||
CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_unit_quantity
|
||||
FOREIGN KEY (id_unit_quantity)
|
||||
REFERENCES Shop_Unit_Measurement(id_unit_measurement),
|
||||
quantity_produced FLOAT NULL,
|
||||
latency_manufacture_days INT NOT NULL,
|
||||
display_order INT NOT NULL,
|
||||
active BIT NOT NULL,
|
||||
name_error VARCHAR(200) NOT NULL
|
||||
);
|
||||
|
||||
CREATE 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
|
||||
);
|
||||
|
||||
|
||||
-- Argument validation
|
||||
# User ID
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF ISNULL(a_id_user) OR NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = a_id_user) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
VALUES
|
||||
(a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', IFNULL(a_id_user, 'NULL')))
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
# Order ID
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF ISNULL(a_id_order) OR ((a_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Manufacturing_Purchase_Order WHERE id_order = a_id_order)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
VALUES
|
||||
(a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Manufacturing Purchase Order ID: ', IFNULL(a_id_order, 'NULL')))
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
/*
|
||||
# Supplier ID
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF ISNULL(a_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = a_id_supplier_ordered) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
VALUES
|
||||
(a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid supplier ID: ', IFNULL(a_id_supplier_ordered, 'NULL')))
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
*/
|
||||
|
||||
# Currency ID
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF ISNULL(a_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency_cost) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
VALUES
|
||||
(a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', IFNULL(a_id_currency, 'NULL')))
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
# Comment
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF ISNULL(a_comment) OR TRIM(a_comment) = '' THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
VALUES
|
||||
(a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.')
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
-- Get data from Temp table
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
SET v_is_new_manufacturing_purchase_order := CASE WHEN a_id_order <= 0 THEN 1 ELSE 0 END;
|
||||
|
||||
INSERT INTO tmp_Shop_Manufacturing_Purchase_Order_Product_Link (
|
||||
id_link,
|
||||
id_order,
|
||||
id_permutation,
|
||||
cost_total_local,
|
||||
id_currency_cost,
|
||||
quantity_used,
|
||||
id_unit_quantity,
|
||||
quantity_produced,
|
||||
value_produced_total_local,
|
||||
latency_manufacture_days,
|
||||
display_order,
|
||||
active,
|
||||
name_error
|
||||
)
|
||||
/*
|
||||
VALUES
|
||||
(a_id_supplier, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active)
|
||||
*/
|
||||
SELECT
|
||||
MPOPL_T.id_link,
|
||||
MPOPL_T.id_order,
|
||||
MPOPL_T.id_permutation,
|
||||
PP.cost_local * MPOPL_T.quantity_used AS cost_total_local,
|
||||
MPOPL_T.id_currency_cost,
|
||||
MPOPL_T.quantity_used,
|
||||
MPOPL_T.id_unit_quantity,
|
||||
MPOPL_T.quantity_produced,
|
||||
(PP.cost_local + PP.profit_local_min) * MPOPL_T.quantity_produced AS value_produced_total_local,
|
||||
MPOPL_T.latency_manufacture_days,
|
||||
MPOPL_T.display_order,
|
||||
MPOPL_T.active,
|
||||
CONCAT(PP.id_permutation, ' - ', IFNULL(P.name ,'')) AS name_error
|
||||
FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T
|
||||
INNER JOIN Shop_Product_Permutation PP ON MPOPL_T.id_permutation = PP.id_permutation
|
||||
INNER JOIN Shop_Product P ON PP.id_product = P.id_product
|
||||
WHERE MPOPL_T.GUID = a_guid
|
||||
-- GROUP BY MPOPL_T.id_order, name_error, MPOPL_T.id_link
|
||||
/*
|
||||
group by
|
||||
MPOPL_T.id_link,
|
||||
MPOPL_T.id_order,
|
||||
MPOPL_T.id_permutation,
|
||||
cost_total_local,
|
||||
MPOPL_T.id_currency_cost,
|
||||
MPOPL_T.quantity_used,
|
||||
MPOPL_T.id_unit_quantity,
|
||||
MPOPL_T.quantity_produced,
|
||||
value_produced_total_local,
|
||||
MPOPL_T.latency_manufacture_days,
|
||||
MPOPL_T.display_order,
|
||||
MPOPL_T.active,
|
||||
name_error
|
||||
*/
|
||||
-- GROUP BY id_link, P.id_product, PP.id_permutation
|
||||
-- GROUP BY name_error, ID_LINK, cost_total_local, value_produced_total_local
|
||||
;
|
||||
DELETE MPOPL_T
|
||||
FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T
|
||||
WHERE MPOPL_T.GUID = a_guid
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- Invalid quantity used
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF EXISTS (
|
||||
SELECT *
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link
|
||||
WHERE
|
||||
NOT ISNULL(quantity_used)
|
||||
AND quantity_used < 0
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
v_id_error_type_bad_data,
|
||||
v_code_error_type_bad_data,
|
||||
CONCAT('Invalid quantity used property for the following permutations: ', GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', '))
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL
|
||||
WHERE t_MPOPL.quantity_used < 0
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Invalid quantity produced
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF EXISTS (
|
||||
SELECT *
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link
|
||||
WHERE
|
||||
NOT ISNULL(quantity_produced)
|
||||
AND quantity_produced < 0
|
||||
) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
v_id_error_type_bad_data,
|
||||
v_code_error_type_bad_data,
|
||||
CONCAT('Invalid quantity produced property for the following permutations: ', GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', '))
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL
|
||||
WHERE t_MPOPL.quantity_produced < 0
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Duplicates
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
v_id_error_type_bad_data,
|
||||
v_code_error_type_bad_data,
|
||||
CONCAT('Duplicate records: ', GROUP_CONCAT(t_MPOPLC.name_error SEPARATOR ', '))
|
||||
FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
SET v_ids_product := (
|
||||
SELECT GROUP_CONCAT(G.id_product SEPARATOR ',')
|
||||
FROM (
|
||||
SELECT DISTINCT PP.id_product
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPO
|
||||
INNER JOIN Shop_Product_Permutation PP ON t_MPO.id_permutation = PP.id_permutation
|
||||
) G
|
||||
);
|
||||
|
||||
CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product);
|
||||
|
||||
/*
|
||||
UPDATE tmp_Shop_Supplier t_S
|
||||
INNER JOIN Shop_Calc_User_Temp TP
|
||||
ON TP.GUID = v_guid_permission
|
||||
SET tP.can_view = TP.can_view,
|
||||
tP.can_edit = TP.can_edit,
|
||||
tP.can_admin = TP.can_admin;
|
||||
*/
|
||||
/*
|
||||
SET v_has_permission := (
|
||||
SELECT can_edit
|
||||
FROM Shop_Calc_User_Temp
|
||||
WHERE
|
||||
GUID = v_guid_permission
|
||||
AND can_edit = 0
|
||||
);
|
||||
|
||||
IF v_has_permission = 0 THEN
|
||||
SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION');
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, msg
|
||||
)
|
||||
SELECT
|
||||
a_guid,
|
||||
v_id_error_type_no_permission,
|
||||
CONCAT('You do not have ', name, ' permissions.')
|
||||
FROM Shop_Permission
|
||||
WHERE id_permission = v_id_permission_manufacturing_purchase_order
|
||||
;
|
||||
END IF;
|
||||
*/
|
||||
SET v_ids_product_no_permission := (
|
||||
SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',')
|
||||
FROM Shop_Calc_User_Temp PT
|
||||
WHERE
|
||||
PT.can_edit = 0
|
||||
AND NOT ISNULL(PT.id_product)
|
||||
);
|
||||
IF NOT ISNULL(v_ids_product_no_permission) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid, id_type, code, msg
|
||||
)
|
||||
VALUES (
|
||||
a_guid,
|
||||
v_id_error_type_no_permission,
|
||||
v_code_error_type_no_permission,
|
||||
CONCAT('You do not have permission to edit the following product IDs: ', v_ids_product_no_permission)
|
||||
)
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Transaction
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
START TRANSACTION;
|
||||
INSERT INTO Shop_Sales_And_Purchasing_Change_Set (
|
||||
comment,
|
||||
updated_last_by,
|
||||
updated_last_on
|
||||
)
|
||||
VALUES (
|
||||
CONCAT(
|
||||
'Save ',
|
||||
CASE WHEN v_is_new_manufacturing_purchase_order = 1 THEN 'new ' ELSE '' END,
|
||||
'Manufacturing Purchase Order - ',
|
||||
a_comment
|
||||
),
|
||||
a_id_user,
|
||||
CURRENT_TIME()
|
||||
);
|
||||
|
||||
SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1);
|
||||
|
||||
IF (v_is_new_manufacturing_purchase_order = 1) THEN
|
||||
INSERT INTO Shop_Manufacturing_Purchase_Order (
|
||||
-- id_supplier_ordered,
|
||||
cost_total_local,
|
||||
id_currency_cost,
|
||||
value_produced_total_local,
|
||||
created_by,
|
||||
id_change_set,
|
||||
active
|
||||
)
|
||||
SELECT
|
||||
-- a_id_supplier_ordered,
|
||||
SUM(t_MPOPL.cost_total_local),
|
||||
a_id_currency_cost,
|
||||
SUM(t_MPOPL.value_produced_total_local),
|
||||
a_id_user,
|
||||
v_id_change_set,
|
||||
a_active
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL
|
||||
;
|
||||
-- SET v_id_order_new
|
||||
SET a_id_order := (SELECT id_order FROM Shop_Manufacturing_Purchase_Order ORDER BY id_order DESC LIMIT 1);
|
||||
|
||||
INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link (
|
||||
id_order,
|
||||
id_permutation,
|
||||
cost_total_local,
|
||||
value_produced_total_local,
|
||||
id_currency_cost,
|
||||
quantity_used,
|
||||
id_unit_quantity,
|
||||
quantity_produced,
|
||||
latency_manufacture_days,
|
||||
display_order,
|
||||
active,
|
||||
created_by,
|
||||
id_change_set
|
||||
)
|
||||
SELECT
|
||||
a_id_order, -- v_id_order_new,
|
||||
id_permutation,
|
||||
cost_total_local,
|
||||
value_produced_total_local,
|
||||
id_currency_cost,
|
||||
quantity_used,
|
||||
id_unit_quantity,
|
||||
quantity_produced,
|
||||
latency_manufacture_days,
|
||||
display_order,
|
||||
active,
|
||||
a_id_user,
|
||||
v_id_change_set
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL
|
||||
;
|
||||
ELSE
|
||||
UPDATE Shop_Manufacturing_Purchase_Order MPO
|
||||
INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPO.id_order = t_MPOPL.id_order
|
||||
SET
|
||||
-- MPO.id_supplier_ordered = a_id_supplier_ordered,
|
||||
MPO.cost_total_local = SUM(t_MPOPL.cost_total_local),
|
||||
MPO.value_produced_total_local = SUM(t_MPOPL.value_produced_total_local),
|
||||
MPO.id_currency = a_id_currency_cost,
|
||||
MPO.id_change_set = v_id_change_set,
|
||||
MPO.active = a_active
|
||||
WHERE MPO.id_order = a_id_order
|
||||
;
|
||||
IF EXISTS (SELECT * FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL INNER JOIN Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link) THEN
|
||||
UPDATE Shop_Manufacturing_Purchase_Order_Product_Link MPOPL
|
||||
INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL
|
||||
ON MPOPL.id_link = t_MPOPL.id_link
|
||||
SET
|
||||
MPOPL.id_order = t_MPOPL.id_order,
|
||||
MPOPL.id_permutation = t_MPOPL.id_permutation,
|
||||
MPOPL.cost_total_local = t_MPOPL.cost_total_local,
|
||||
MPOPL.value_produced_total_local = t_MPOPL.value_produced_total_local,
|
||||
MPOPL.id_currency_cost = t_MPOPL.id_currency_cost,
|
||||
MPOPL.quantity_used = t_MPOPL.quantity_used,
|
||||
MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity,
|
||||
MPOPL.quantity_produced = t_MPOPL.quantity_produced,
|
||||
MPOPL.latency_manufacture_days = t_MPOPL.latency_manufacture_days,
|
||||
MPOPL.display_order = t_MPOPL.display_order,
|
||||
MPOPL.active = t_MPOPL.active,
|
||||
MPOPL.id_change_set = v_id_change_set
|
||||
;
|
||||
ELSE
|
||||
INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link (
|
||||
id_order,
|
||||
id_permutation,
|
||||
cost_total_local,
|
||||
value_produced_total_local,
|
||||
id_currency_cost,
|
||||
quantity_used,
|
||||
id_unit_quantity,
|
||||
quantity_produced,
|
||||
latency_manufacture_days,
|
||||
display_order,
|
||||
active,
|
||||
created_by,
|
||||
id_change_set
|
||||
)
|
||||
SELECT
|
||||
id_order,
|
||||
id_permutation,
|
||||
cost_total_local,
|
||||
value_produced_total_local,
|
||||
id_currency_cost,
|
||||
quantity_used,
|
||||
id_unit_quantity,
|
||||
quantity_produced,
|
||||
latency_manufacture_days,
|
||||
display_order,
|
||||
active,
|
||||
a_id_user,
|
||||
v_id_change_set
|
||||
FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL
|
||||
WHERE t_MPOPL.id_link < 0
|
||||
;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
ROLLBACK;
|
||||
ELSE
|
||||
COMMIT;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Returns
|
||||
# SET v_now = NOW();
|
||||
|
||||
# Manufacturing Purchase Orders
|
||||
SELECT *
|
||||
FROM Shop_Manufacturing_Purchase_Order
|
||||
WHERE
|
||||
id_order = a_id_order
|
||||
-- GUID = a_guid
|
||||
;
|
||||
|
||||
# Manufacturing Purchase Order Product Links
|
||||
SELECT *
|
||||
FROM Shop_Manufacturing_Purchase_Order_Product_Link
|
||||
WHERE
|
||||
id_order = a_id_order
|
||||
-- GUID = a_guid
|
||||
;
|
||||
|
||||
# Errors
|
||||
SELECT *
|
||||
FROM tmp_Msg_Error
|
||||
;
|
||||
|
||||
# DROP TABLE tmp_Shop_Manufacturing_Purchase_Order;
|
||||
DROP TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link;
|
||||
DROP TABLE tmp_Msg_Error;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Audit;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order;
|
||||
|
||||
INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Temp (
|
||||
guid,
|
||||
id_link,
|
||||
id_order,
|
||||
id_permutation,
|
||||
cost_total_local,
|
||||
id_currency_cost,
|
||||
quantity_used,
|
||||
id_unit_quantity,
|
||||
quantity_produced,
|
||||
latency_manufacture_days,
|
||||
display_order,
|
||||
active
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
'NIPS', # guid
|
||||
-1, # id_link,
|
||||
-1, # id_order,
|
||||
1, # id_permutation,
|
||||
100, # cost_total_local,
|
||||
1, # id_currency_cost,
|
||||
1, # quantity_used,
|
||||
1, # id_unit_quantity,
|
||||
1, # quantity_produced,
|
||||
14, # latency_manufacture_days ,
|
||||
1, # display_order
|
||||
1 # active
|
||||
)
|
||||
;
|
||||
|
||||
SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp;
|
||||
|
||||
CALL p_shop_save_manufacturing_purchase_order (
|
||||
'NIPS', # a_guid
|
||||
'auth0|6582b95c895d09a70ba10fef', # a_id_user
|
||||
-1, # a_id_order
|
||||
1, # a_id_currency_cost
|
||||
1, # a_active
|
||||
'Initial data' # a_comment
|
||||
);
|
||||
|
||||
SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp;
|
||||
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order_Audit;
|
||||
DELETE FROM Shop_Manufacturing_Purchase_Order;
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@@ -342,11 +342,11 @@ BEGIN
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
|
||||
|
||||
CALL p_shop_user_eval(a_guid, a_id_user, FALSE, v_id_permission_product, v_id_access_level_edit, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(a_guid, a_id_user, FALSE, v_id_permission_product, v_id_access_level_edit, v_ids_product_permission);
|
||||
|
||||
UPDATE tmp_Permutation t_P
|
||||
INNER JOIN Shop_Product P ON t_P.id_product = P.id_product
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON P.id_product = UE_T.id_product
|
||||
AND UE_T.GUID = a_guid
|
||||
SET
|
||||
@@ -355,7 +355,7 @@ BEGIN
|
||||
, t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_clear_shop_user_eval_temp(a_guid);
|
||||
CALL p_shop_clear_calc_user(a_guid);
|
||||
|
||||
IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.can_edit) LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
|
||||
@@ -80,7 +80,7 @@ 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_ids_variation_type, ',');
|
||||
CALL p_split(a_guid, 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 (
|
||||
@@ -99,7 +99,7 @@ BEGIN
|
||||
|
||||
CALL p_clear_split_temp;
|
||||
|
||||
CALL p_split(a_ids_variation, ',');
|
||||
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 (
|
||||
@@ -190,13 +190,13 @@ BEGIN
|
||||
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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(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, v_id_permission_variation, v_id_access_level_view, '');
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
|
||||
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,
|
||||
code,
|
||||
@@ -210,7 +210,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
CALL p_clear_shop_user_eval_temp(v_guid);
|
||||
CALL p_shop_clear_calc_user(v_guid);
|
||||
END IF;
|
||||
|
||||
IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
|
||||
@@ -0,0 +1,842 @@
|
||||
|
||||
|
||||
-- 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
|
||||
*/
|
||||
557
static/MySQL/7219_p_shop_get_many_stock_item-staging.sql
Normal file
557
static/MySQL/7219_p_shop_get_many_stock_item-staging.sql
Normal file
@@ -0,0 +1,557 @@
|
||||
|
||||
|
||||
-- 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
|
||||
*/
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item;
|
||||
|
||||
@@ -9,33 +7,20 @@ 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_inactive_product_permutation BIT,
|
||||
IN a_ids_product_permutation TEXT,
|
||||
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_ids_region_storage TEXT,
|
||||
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_ids_plant_storage TEXT,
|
||||
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,
|
||||
@@ -43,13 +28,10 @@ CREATE PROCEDURE p_shop_get_many_stock_item (
|
||||
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
|
||||
IN a_get_nonconsumed_stock_item_only BIT,
|
||||
IN a_test 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;
|
||||
@@ -72,35 +54,23 @@ BEGIN
|
||||
|
||||
-- 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_guid_permutations := IFNULL(a_guid_permutations, '');
|
||||
SET a_get_inactive_product_permutation := IFNULL(a_get_inactive_product_permutation, 0);
|
||||
SET a_ids_product_permutation := IFNULL(a_ids_product_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_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);
|
||||
@@ -114,122 +84,39 @@ BEGIN
|
||||
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
|
||||
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
|
||||
-- , rank_permutation INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Stock_Item (
|
||||
id_stock INT NOT NULL PRIMARY KEY,
|
||||
id_permutation INT NOT NULL
|
||||
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
|
||||
/*
|
||||
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
|
||||
@@ -241,10 +128,11 @@ BEGIN
|
||||
, active_permutation BIT NOT NULL
|
||||
, active_product BIT NOT NULL
|
||||
, active_category BIT NOT NULL
|
||||
, rank_stock_item INT 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
|
||||
@@ -257,7 +145,7 @@ BEGIN
|
||||
FOREIGN KEY (id_region)
|
||||
REFERENCES Shop_Region(id_region)
|
||||
*/
|
||||
, rank_region INT NOT NULL
|
||||
-- , rank_region INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Plant_Storage (
|
||||
@@ -267,7 +155,7 @@ BEGIN
|
||||
FOREIGN KEY (id_plant)
|
||||
REFERENCES Shop_Plant(id_plant)
|
||||
*/
|
||||
, rank_plant INT NOT NULL
|
||||
-- , rank_plant INT NOT NULL
|
||||
, id_region INT NOT NULL
|
||||
);
|
||||
|
||||
@@ -278,7 +166,7 @@ BEGIN
|
||||
FOREIGN KEY (id_location)
|
||||
REFERENCES Shop_Location_Storage(id_location)
|
||||
*/
|
||||
, rank_location INT NOT NULL
|
||||
-- , rank_location INT NOT NULL
|
||||
, id_plant INT NOT NULL
|
||||
);
|
||||
|
||||
@@ -297,9 +185,7 @@ BEGIN
|
||||
|
||||
|
||||
-- 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_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END; -- 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;
|
||||
@@ -307,216 +193,85 @@ 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
|
||||
)
|
||||
;
|
||||
|
||||
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
|
||||
id_product,
|
||||
id_location_storage
|
||||
)
|
||||
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
|
||||
t_PP.id_permutation,
|
||||
t_PP.id_product,
|
||||
SI.id_location_storage
|
||||
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
|
||||
INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation
|
||||
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
|
||||
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
|
||||
)
|
||||
)
|
||||
# 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
|
||||
)
|
||||
)
|
||||
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
|
||||
)
|
||||
;
|
||||
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
|
||||
@@ -550,46 +305,30 @@ BEGIN
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
DISTINCT R.id_region,
|
||||
RANK() OVER (ORDER BY R.id_region) AS rank_region
|
||||
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
|
||||
;
|
||||
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 (
|
||||
@@ -622,36 +361,29 @@ BEGIN
|
||||
)
|
||||
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_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_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(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, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
UPDATE tmp_Stock_Item t_SI
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
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,
|
||||
@@ -662,7 +394,7 @@ BEGIN
|
||||
DELETE t_SI
|
||||
FROM tmp_Stock_Item t_SI
|
||||
/*
|
||||
LEFT JOIN Shop_User_Eval_Temp UE_T
|
||||
LEFT JOIN Shop_Calc_User_Temp UE_T
|
||||
ON t_SI.id_product = UE_T.id_product
|
||||
AND UE_T.GUID = v_guid
|
||||
*/
|
||||
@@ -670,8 +402,8 @@ BEGIN
|
||||
/*
|
||||
FIND_IN_SET(t_SI.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), '%');
|
||||
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)
|
||||
@@ -679,20 +411,28 @@ BEGIN
|
||||
*/
|
||||
t_SI.id_product NOT IN (
|
||||
SELECT id_product
|
||||
FROM Shop_User_Eval_Temp UE_T
|
||||
FROM Shop_Calc_User_Temp UE_T
|
||||
WHERE
|
||||
GUID = v_guid
|
||||
AND IFNULL(can_view, 0) = 1
|
||||
)
|
||||
;
|
||||
|
||||
# CALL p_shop_user_eval_clear_temp(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
# 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();
|
||||
@@ -700,72 +440,46 @@ BEGIN
|
||||
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,
|
||||
P.id_product,
|
||||
P.id_category,
|
||||
t_SI.id_location_storage,
|
||||
SL.name AS name_location_storage,
|
||||
t_SI.id_currency_cost,
|
||||
t_PS.id_plant,
|
||||
t_RS.id_region,
|
||||
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,
|
||||
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_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 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 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 P ON t_PS.id_plant = P.id_plant
|
||||
INNER JOIN Shop_Address A ON P.id_address = A.id_address
|
||||
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 t_SI.id_currency_cost = CURRENCY.id_currency
|
||||
INNER JOIN Shop_Currency CURRENCY ON SI.id_currency_cost = CURRENCY.id_currency
|
||||
WHERE
|
||||
IFNULL(t_SI.can_view, 0) = 1
|
||||
ORDER BY t_SI.rank_stock_item
|
||||
;
|
||||
|
||||
# Variations
|
||||
SELECT
|
||||
V.id_variation,
|
||||
VT.id_type,
|
||||
t_SI.id_stock_item,
|
||||
t_SI.id_permutation,
|
||||
t_SI.id_product,
|
||||
t_SI.id_category,
|
||||
VT.code AS code_variation_type,
|
||||
VT.name AS name_variation_type,
|
||||
V.code AS code_variation,
|
||||
V.name AS name_variation,
|
||||
RANK() OVER (ORDER BY t_SI.rank_permutation, PPVL.display_order) AS display_order
|
||||
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_Stock_Item t_SI ON PPVL.id_permutation = t_SI.id_permutation
|
||||
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 tmp_Region_Storage t_RS ON t_PS.id_region = t_RS.id_region
|
||||
WHERE
|
||||
V.active
|
||||
AND PPVL.active
|
||||
;
|
||||
|
||||
# Errors
|
||||
SELECT
|
||||
@@ -805,45 +519,30 @@ 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_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_id_user
|
||||
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
|
||||
-- 'nips', # a_guid_permutations
|
||||
0, # a_get_inactive_product_permutation
|
||||
'', # a_ids_product_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
|
||||
1, # 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
|
||||
1, # 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
|
||||
1, # 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
|
||||
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
|
||||
@@ -852,11 +551,12 @@ CALL p_shop_get_many_stock_item (
|
||||
0 # a_get_nonconsumed_stock_item_only
|
||||
);
|
||||
|
||||
/*
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS tmp_Msg_Error;
|
||||
|
||||
select * from shop_image;
|
||||
select * from Shop_Storage_Location;
|
||||
select * from shop_product;
|
||||
select * from TMP_MSG_ERROR;
|
||||
DROP TABLE TMP_MSG_ERROR;
|
||||
|
||||
@@ -400,27 +400,27 @@ BEGIN
|
||||
-- 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_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(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, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
UPDATE tmp_Shop_Product t_P
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
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_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
-- select * from tmp_Shop_Product;
|
||||
|
||||
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), '%');
|
||||
FIND_IN_SET(t_P.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), '%');
|
||||
OR (
|
||||
ISNULL(t_P.can_view)
|
||||
AND (
|
||||
@@ -438,10 +438,10 @@ BEGIN
|
||||
)
|
||||
;
|
||||
|
||||
CALL p_clear_shop_user_eval_temp(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
/*
|
||||
DELETE FROM Shop_User_Eval_Temp UE_T
|
||||
DELETE FROM Shop_Calc_User_Temp UE_T
|
||||
WHERE UE_T.GUID = v_guid
|
||||
;
|
||||
*/
|
||||
@@ -780,7 +780,7 @@ CALL partsltd_prod.p_shop_get_many_product_price_and_discount_and_delivery_regio
|
||||
IN a_ids_discount VARCHAR(4000)
|
||||
);
|
||||
|
||||
select * FROM Shop_User_Eval_Temp;
|
||||
select * FROM Shop_Calc_User_Temp;
|
||||
|
||||
select * from Shop_Product_Permutation;
|
||||
select * from shop_product_change_set;
|
||||
@@ -804,8 +804,8 @@ insert into shop_product_change_set (comment)
|
||||
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 * FROM Shop_Calc_User_Temp;
|
||||
select distinct guid
|
||||
-- DELETE
|
||||
FROM Shop_User_Eval_Temp;
|
||||
FROM Shop_Calc_User_Temp;
|
||||
*/
|
||||
|
||||
@@ -145,7 +145,7 @@ BEGIN
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
# SELECT * FROM tmp_Msg_Error LIMIT 1;
|
||||
CALL p_shop_user_eval (
|
||||
CALL p_shop_calc_user (
|
||||
v_guid, # a_guid
|
||||
a_id_user, # a_id_user
|
||||
0, # a_get_inactive_users
|
||||
@@ -156,7 +156,7 @@ BEGIN
|
||||
);
|
||||
# SELECT * FROM tmp_Msg_Error LIMIT 1;
|
||||
|
||||
IF EXISTS (SELECT can_admin FROM Shop_User_Eval_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN
|
||||
IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid,
|
||||
code,
|
||||
@@ -170,7 +170,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE guid = v_guid
|
||||
;
|
||||
END IF;
|
||||
|
||||
@@ -97,7 +97,7 @@ BEGIN
|
||||
a_get_inactive_user
|
||||
OR U.active
|
||||
)
|
||||
/*Shop_User_Eval_Temp UE_T
|
||||
/*Shop_Calc_User_Temp UE_T
|
||||
WHERE 1=1
|
||||
AND UE_T.guid = v_guid
|
||||
AND UE_T.active = 1
|
||||
@@ -115,9 +115,9 @@ BEGIN
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
-- 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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(
|
||||
CALL p_shop_calc_user(
|
||||
v_guid, -- guid
|
||||
a_id_user, -- ids_user
|
||||
FALSE, -- get_inactive_user
|
||||
@@ -126,11 +126,11 @@ BEGIN
|
||||
'' -- ids_product
|
||||
);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT can_view
|
||||
FROM Shop_User_Eval_Temp UE_T
|
||||
FROM Shop_Calc_User_Temp UE_T
|
||||
WHERE 1=1
|
||||
AND UE_T.GUID = v_guid
|
||||
AND UE_T.id_permission_required = v_id_permission_user
|
||||
@@ -180,7 +180,7 @@ BEGIN
|
||||
id_user
|
||||
, id_permission_required
|
||||
, can_admin AS can_admin_store
|
||||
FROM Shop_User_Eval_Temp UE_T_STORE
|
||||
FROM Shop_Calc_User_Temp UE_T_STORE
|
||||
WHERE 1=1
|
||||
AND UE_T_STORE.guid = v_guid
|
||||
AND UE_T_STORE.id_permission_required = v_id_permission_store_admin
|
||||
@@ -190,7 +190,7 @@ BEGIN
|
||||
id_user
|
||||
, id_permission_required
|
||||
, can_admin AS can_admin_user
|
||||
FROM Shop_User_Eval_Temp UE_T_USER
|
||||
FROM Shop_Calc_User_Temp UE_T_USER
|
||||
WHERE 1=1
|
||||
AND UE_T_USER.guid = v_guid
|
||||
AND UE_T_USER.id_permission_required = v_id_permission_user_admin
|
||||
@@ -232,10 +232,10 @@ BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
|
||||
|
||||
/*
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid;
|
||||
*/
|
||||
CALL p_clear_shop_user_eval_temp(v_guid);
|
||||
CALL p_shop_clear_calc_user(v_guid);
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
@@ -251,8 +251,8 @@ 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;
|
||||
select * from Shop_Calc_User_Temp;
|
||||
delete from Shop_Calc_User_Temp;
|
||||
|
||||
SELECT *
|
||||
FROM SHOP_USER;
|
||||
|
||||
@@ -379,7 +379,7 @@ BEGIN
|
||||
-- String product id, permutation id, quantity list
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND
|
||||
# Get product ids
|
||||
CALL p_split(a_ids_permutation_basket, ',');
|
||||
CALL p_split(a_guid, a_ids_permutation_basket, ',');
|
||||
INSERT INTO tmp_Shop_Product (
|
||||
id_product, id_permutation, display_order
|
||||
)
|
||||
@@ -397,7 +397,7 @@ BEGIN
|
||||
DROP TABLE Split_Temp;
|
||||
|
||||
# Get product quantities
|
||||
CALL p_split(a_quantities_permutation_basket, ',');
|
||||
CALL p_split(a_guid, a_quantities_permutation_basket, ',');
|
||||
INSERT INTO tmp_Shop_Quantity (
|
||||
quantity, display_order
|
||||
)
|
||||
|
||||
@@ -158,17 +158,17 @@ BEGIN
|
||||
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
CALL p_shop_user_eval(v_guid_permission, v_id_user, v_id_permission_supplier, '');
|
||||
CALL p_shop_calc_user(v_guid_permission, v_id_user, v_id_permission_supplier, '');
|
||||
|
||||
/*
|
||||
UPDATE tmp_Shop_Supplier t_S
|
||||
INNER JOIN Shop_User_Eval_Temp TP
|
||||
INNER JOIN Shop_Calc_User_Temp TP
|
||||
ON TP.GUID = v_guid_permission
|
||||
SET tP.can_view = TP.can_view,
|
||||
tP.can_edit = TP.can_edit,
|
||||
tP.can_admin = TP.can_admin;
|
||||
*/
|
||||
SET v_has_permission := (SELECT can_edit FROM Shop_User_Eval_Temp WHERE GUID = v_guid_permission);
|
||||
SET v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission);
|
||||
|
||||
IF v_has_permission = 0 THEN
|
||||
SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION');
|
||||
@@ -184,9 +184,9 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_user_eval_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
END IF;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ BEGIN
|
||||
-- select v_has_filter_product, v_has_filter_permutation;
|
||||
|
||||
IF v_has_filter_supplier = 1 OR a_get_all_supplier = 1 THEN
|
||||
CALL p_split(a_ids_supplier, ',');
|
||||
CALL p_split(a_guid, a_ids_supplier, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp S_T LEFT JOIN Shop_Supplier S ON S_T.substring = S.id_supplier WHERE ISNULL(S.id_supplier)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -154,13 +154,13 @@ BEGIN
|
||||
SET v_id_permission_supplier := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER' 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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(v_guid, a_id_user, FALSE, v_id_permission_supplier, v_id_access_level_view, '');
|
||||
CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_supplier, v_id_access_level_view, '');
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
|
||||
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,
|
||||
code,
|
||||
|
||||
@@ -271,11 +271,11 @@ BEGIN
|
||||
) G
|
||||
);
|
||||
|
||||
CALL p_shop_user_eval(v_guid_permission, a_id_user, 0, v_id_permission_supplier_purchase_order, v_id_access_level_edit, v_ids_product);
|
||||
CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_supplier_purchase_order, v_id_access_level_edit, v_ids_product);
|
||||
|
||||
/*
|
||||
UPDATE tmp_Shop_Supplier t_S
|
||||
INNER JOIN Shop_User_Eval_Temp TP
|
||||
INNER JOIN Shop_Calc_User_Temp TP
|
||||
ON TP.GUID = v_guid_permission
|
||||
SET tP.can_view = TP.can_view,
|
||||
tP.can_edit = TP.can_edit,
|
||||
@@ -284,7 +284,7 @@ BEGIN
|
||||
/*
|
||||
SET v_has_permission := (
|
||||
SELECT can_edit
|
||||
FROM Shop_User_Eval_Temp
|
||||
FROM Shop_Calc_User_Temp
|
||||
WHERE
|
||||
GUID = v_guid_permission
|
||||
AND can_edit = 0
|
||||
@@ -306,7 +306,7 @@ BEGIN
|
||||
*/
|
||||
SET v_ids_product_no_permission := (
|
||||
SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',')
|
||||
FROM Shop_User_Eval_Temp PT
|
||||
FROM Shop_Calc_User_Temp PT
|
||||
WHERE
|
||||
PT.can_edit = 0
|
||||
AND NOT ISNULL(PT.id_product)
|
||||
@@ -324,7 +324,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
END IF;
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ BEGIN
|
||||
-- select v_has_filter_product, v_has_filter_permutation;
|
||||
|
||||
IF v_has_filter_supplier THEN
|
||||
CALL p_split(a_ids_supplier, ',');
|
||||
CALL p_split(a_guid, a_ids_supplier, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Supplier S ON TS.substring = S.id_supplier WHERE ISNULL(S.id_supplier)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -291,7 +291,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_category = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_category, ',');
|
||||
CALL p_split(a_guid, a_ids_category, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category WHERE ISNULL(C.id_category)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -317,7 +317,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_product = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_product, ',');
|
||||
CALL p_split(a_guid, a_ids_product, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product ON TS.substring = P.id_product WHERE ISNULL(P.id_product)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -343,7 +343,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_permutation = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_permutation, ',');
|
||||
CALL p_split(a_guid, a_ids_permutation, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation WHERE ISNULL(PP.id_permutation)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -476,7 +476,7 @@ BEGIN
|
||||
|
||||
-- Get orders
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_order, ',');
|
||||
CALL p_split(a_guid, a_ids_order, ',');
|
||||
|
||||
IF v_has_filter_order AND EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Supplier_Purchase_Order SPO ON TS.substring = SPO.id_order WHERE ISNULL(SPO.id_order)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -582,13 +582,13 @@ BEGIN
|
||||
SET v_ids_product_permission := (SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P);
|
||||
|
||||
-- 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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(v_guid, a_id_user, FALSE, v_ids_permission_supplier_purchase_order, v_id_access_level_view, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_supplier_purchase_order, v_id_access_level_view, v_ids_product_permission);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
|
||||
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,
|
||||
id_type,
|
||||
@@ -607,7 +607,7 @@ BEGIN
|
||||
|
||||
|
||||
UPDATE tmp_Shop_Product t_P
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation
|
||||
AND UE_T.GUID = v_guid
|
||||
SET t_P.can_view = UE_T.can_view,
|
||||
@@ -615,9 +615,9 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_user_eval_clear_temp(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
# 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;
|
||||
@@ -722,7 +722,7 @@ BEGIN
|
||||
DROP TABLE IF EXISTS tmp_Shop_Supplier;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
;
|
||||
END //
|
||||
|
||||
@@ -309,11 +309,11 @@ BEGIN
|
||||
) G
|
||||
);
|
||||
|
||||
CALL p_shop_user_eval(v_guid_permission, a_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product);
|
||||
CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product);
|
||||
|
||||
/*
|
||||
UPDATE tmp_Shop_Supplier t_S
|
||||
INNER JOIN Shop_User_Eval_Temp TP
|
||||
INNER JOIN Shop_Calc_User_Temp TP
|
||||
ON TP.GUID = v_guid_permission
|
||||
SET tP.can_view = TP.can_view,
|
||||
tP.can_edit = TP.can_edit,
|
||||
@@ -322,7 +322,7 @@ BEGIN
|
||||
/*
|
||||
SET v_has_permission := (
|
||||
SELECT can_edit
|
||||
FROM Shop_User_Eval_Temp
|
||||
FROM Shop_Calc_User_Temp
|
||||
WHERE
|
||||
GUID = v_guid_permission
|
||||
AND can_edit = 0
|
||||
@@ -344,7 +344,7 @@ BEGIN
|
||||
*/
|
||||
SET v_ids_product_no_permission := (
|
||||
SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',')
|
||||
FROM Shop_User_Eval_Temp PT
|
||||
FROM Shop_Calc_User_Temp PT
|
||||
WHERE
|
||||
PT.can_edit = 0
|
||||
AND NOT ISNULL(PT.id_product)
|
||||
|
||||
@@ -211,7 +211,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_category = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_category, ',');
|
||||
CALL p_split(a_guid, a_ids_category, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category WHERE ISNULL(C.id_category)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -237,7 +237,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_product = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_product, ',');
|
||||
CALL p_split(a_guid, a_ids_product, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product ON TS.substring = P.id_product WHERE ISNULL(P.id_product)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -263,7 +263,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_permutation = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_permutation, ',');
|
||||
CALL p_split(a_guid, a_ids_permutation, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation WHERE ISNULL(PP.id_permutation)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -396,7 +396,7 @@ BEGIN
|
||||
|
||||
-- Get orders
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_order, ',');
|
||||
CALL p_split(a_guid, a_ids_order, ',');
|
||||
|
||||
IF v_has_filter_order AND EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Manufacturing_Purchase_Order MPO ON TS.substring = MPO.id_order WHERE ISNULL(MPO.id_order)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -495,13 +495,13 @@ BEGIN
|
||||
SET v_ids_product_permission := (SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P);
|
||||
|
||||
-- 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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(v_guid, a_id_user, FALSE, v_ids_permission_manufacturing_purchase_order, v_id_access_level_view, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_manufacturing_purchase_order, v_id_access_level_view, v_ids_product_permission);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
|
||||
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,
|
||||
id_type,
|
||||
@@ -520,7 +520,7 @@ BEGIN
|
||||
|
||||
|
||||
UPDATE tmp_Shop_Product t_P
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation
|
||||
AND UE_T.GUID = v_guid
|
||||
SET t_P.can_view = UE_T.can_view,
|
||||
@@ -528,9 +528,9 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_user_eval_clear_temp(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
# 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;
|
||||
@@ -617,7 +617,7 @@ BEGIN
|
||||
DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
;
|
||||
END //
|
||||
|
||||
@@ -154,17 +154,17 @@ BEGIN
|
||||
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
|
||||
CALL p_shop_user_eval(v_guid_permission, a_id_user, 0, v_id_permission_customer, v_id_access_level_edit, '');
|
||||
CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_customer, v_id_access_level_edit, '');
|
||||
|
||||
/*
|
||||
UPDATE tmp_Shop_Customer t_S
|
||||
INNER JOIN Shop_User_Eval_Temp TP
|
||||
INNER JOIN Shop_Calc_User_Temp TP
|
||||
ON TP.GUID = v_guid_permission
|
||||
SET tP.can_view = TP.can_view,
|
||||
tP.can_edit = TP.can_edit,
|
||||
tP.can_admin = TP.can_admin;
|
||||
*/
|
||||
SET v_has_permission := (SELECT can_edit FROM Shop_User_Eval_Temp WHERE GUID = v_guid_permission);
|
||||
SET v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission);
|
||||
|
||||
IF v_has_permission = 0 THEN
|
||||
SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION');
|
||||
@@ -180,9 +180,9 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_user_eval_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
END IF;
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ BEGIN
|
||||
-- select v_has_filter_product, v_has_filter_permutation;
|
||||
|
||||
IF v_has_filter_customer = 1 OR a_get_all_customer = 1 THEN
|
||||
CALL p_split(a_ids_customer, ',');
|
||||
CALL p_split(a_guid, a_ids_customer, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp S_T LEFT JOIN Shop_Customer C ON S_T.substring = C.id_customer WHERE ISNULL(C.id_customer)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -165,13 +165,13 @@ BEGIN
|
||||
SET v_id_permission_customer := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' 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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(v_guid, a_id_user, FALSE, v_id_permission_customer, v_id_access_level_view, '');
|
||||
CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_customer, v_id_access_level_view, '');
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
|
||||
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,
|
||||
id_type,
|
||||
@@ -249,7 +249,7 @@ BEGIN
|
||||
-- Clean up
|
||||
DROP TABLE IF EXISTS tmp_Shop_Customer;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
;
|
||||
END //
|
||||
|
||||
@@ -270,11 +270,11 @@ BEGIN
|
||||
) G
|
||||
);
|
||||
|
||||
CALL p_shop_user_eval(v_guid_permission, a_id_user, 0, v_id_permission_Customer_Sales_order, v_id_access_level_edit, v_ids_product);
|
||||
CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_Customer_Sales_order, v_id_access_level_edit, v_ids_product);
|
||||
|
||||
/*
|
||||
UPDATE tmp_Shop_Supplier t_S
|
||||
INNER JOIN Shop_User_Eval_Temp TP
|
||||
INNER JOIN Shop_Calc_User_Temp TP
|
||||
ON TP.GUID = v_guid_permission
|
||||
SET tP.can_view = TP.can_view,
|
||||
tP.can_edit = TP.can_edit,
|
||||
@@ -283,7 +283,7 @@ BEGIN
|
||||
/*
|
||||
SET v_has_permission := (
|
||||
SELECT can_edit
|
||||
FROM Shop_User_Eval_Temp
|
||||
FROM Shop_Calc_User_Temp
|
||||
WHERE
|
||||
GUID = v_guid_permission
|
||||
AND can_edit = 0
|
||||
@@ -305,7 +305,7 @@ BEGIN
|
||||
*/
|
||||
SET v_ids_product_no_permission := (
|
||||
SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',')
|
||||
FROM Shop_User_Eval_Temp PT
|
||||
FROM Shop_Calc_User_Temp PT
|
||||
WHERE
|
||||
PT.can_edit = 0
|
||||
AND NOT ISNULL(PT.id_product)
|
||||
@@ -323,7 +323,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
END IF;
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ BEGIN
|
||||
-- select v_has_filter_product, v_has_filter_permutation;
|
||||
|
||||
IF v_has_filter_customer = 1 OR a_get_all_customer = 1 THEN
|
||||
CALL p_split(a_ids_customer, ',');
|
||||
CALL p_split(a_guid, a_ids_customer, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Customer S ON TS.substring = S.id_customer WHERE ISNULL(S.id_customer)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -301,7 +301,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_category = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_category, ',');
|
||||
CALL p_split(a_guid, a_ids_category, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category WHERE ISNULL(C.id_category)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -327,7 +327,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_product = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_product, ',');
|
||||
CALL p_split(a_guid, a_ids_product, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product ON TS.substring = P.id_product WHERE ISNULL(P.id_product)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -353,7 +353,7 @@ BEGIN
|
||||
|
||||
IF v_has_filter_permutation = 1 THEN
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_permutation, ',');
|
||||
CALL p_split(a_guid, a_ids_permutation, ',');
|
||||
|
||||
IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation WHERE ISNULL(PP.id_permutation)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -486,7 +486,7 @@ BEGIN
|
||||
|
||||
-- Get orders
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN
|
||||
CALL p_split(a_ids_order, ',');
|
||||
CALL p_split(a_guid, a_ids_order, ',');
|
||||
|
||||
IF v_has_filter_order AND EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Customer_Sales_Order CSO ON TS.substring = CSO.id_order WHERE ISNULL(CSO.id_order)) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
@@ -594,13 +594,13 @@ BEGIN
|
||||
SET v_ids_product_permission := (SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P);
|
||||
|
||||
-- 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;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
CALL p_shop_user_eval(v_guid, a_id_user, FALSE, v_ids_permission_customer_purchase_order, v_id_access_level_view, v_ids_product_permission);
|
||||
CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_customer_purchase_order, v_id_access_level_view, v_ids_product_permission);
|
||||
|
||||
-- select * from Shop_User_Eval_Temp;
|
||||
-- select * from Shop_Calc_User_Temp;
|
||||
|
||||
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
|
||||
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,
|
||||
id_type,
|
||||
@@ -619,7 +619,7 @@ BEGIN
|
||||
|
||||
|
||||
UPDATE tmp_Shop_Product t_P
|
||||
INNER JOIN Shop_User_Eval_Temp UE_T
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation
|
||||
AND UE_T.GUID = v_guid
|
||||
SET t_P.can_view = UE_T.can_view,
|
||||
@@ -627,9 +627,9 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_user_eval_clear_temp(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
# 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;
|
||||
@@ -733,7 +733,7 @@ BEGIN
|
||||
DROP TABLE IF EXISTS tmp_Shop_Customer;
|
||||
DROP TABLE IF EXISTS tmp_Shop_Product;
|
||||
|
||||
DELETE FROM Shop_User_Eval_Temp
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
;
|
||||
END //
|
||||
|
||||
@@ -154,8 +154,8 @@
|
||||
6000_p_split.sql
|
||||
6001_p_clear_split_temp.sql
|
||||
6206_fn_shop_get_product_permutation_name.sql
|
||||
6500_p_shop_user_eval.sql
|
||||
6501_p_clear_shop_user_eval_temp.sql
|
||||
6500_p_shop_calc_user.sql
|
||||
6501_p_shop_clear_calc_user.sql
|
||||
7003_p_shop_get_many_access_level.sql
|
||||
7101_p_shop_get_many_region.sql
|
||||
7116_p_shop_get_many_currency.sql
|
||||
|
||||
Reference in New Issue
Block a user