feat(web): Store Product UI created and hooked up for viewing, editing, and saving.
This commit is contained in:
@@ -7411,7 +7411,7 @@ BEGIN
|
||||
, t_C.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_shop_calc_user_clear_temp(a_guid);
|
||||
CALL p_shop_clear_calc_user(a_guid);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
@@ -7727,7 +7727,7 @@ BEGIN
|
||||
, t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_shop_calc_user_clear_temp(a_guid);
|
||||
CALL p_shop_clear_calc_user(a_guid);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
@@ -11495,7 +11495,7 @@ BEGIN
|
||||
)
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM partsltd_prod.Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
@@ -14368,7 +14368,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
@@ -15903,7 +15903,7 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
@@ -17186,7 +17186,7 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
@@ -17496,7 +17496,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
@@ -19071,7 +19071,7 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -8,9 +8,9 @@ DROP PROCEDURE IF EXISTS p_shop_save_product_category;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_save_product_category (
|
||||
IN a_id_user INT,
|
||||
IN a_comment VARCHAR(500),
|
||||
IN a_guid BINARY(36),
|
||||
IN a_comment VARCHAR(500)
|
||||
IN a_id_user INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE v_code_type_error_bad_data VARCHAR(100);
|
||||
@@ -206,59 +206,59 @@ BEGIN
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
START TRANSACTION;
|
||||
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
INSERT INTO Shop_Product_Change_Set ( comment )
|
||||
VALUES ( a_comment )
|
||||
;
|
||||
|
||||
SET v_id_change_set := LAST_INSERT_ID();
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
INSERT INTO Shop_Product_Change_Set ( comment )
|
||||
VALUES ( a_comment )
|
||||
;
|
||||
|
||||
SET v_id_change_set := LAST_INSERT_ID();
|
||||
|
||||
UPDATE Shop_Product_Category PC
|
||||
INNER JOIN tmp_Category t_C ON PC.id_category = t_C.id_category
|
||||
SET
|
||||
PC.id_category = t_C.id_category
|
||||
, PC.code = t_C.code
|
||||
, PC.name = t_C.name
|
||||
, PC.description = t_C.description
|
||||
, PC.id_access_level_required = t_C.id_access_level_required
|
||||
, PC.active = t_C.active
|
||||
, PC.display_order = t_C.display_order
|
||||
, PC.id_change_set = v_id_change_set
|
||||
;
|
||||
END IF;
|
||||
|
||||
UPDATE Shop_Product_Category PC
|
||||
INNER JOIN tmp_Category t_C ON PC.id_category = t_C.id_category
|
||||
SET
|
||||
PC.id_category = t_C.id_category
|
||||
, PC.code = t_C.code
|
||||
, PC.name = t_C.name
|
||||
, PC.description = t_C.description
|
||||
, PC.id_access_level_required = t_C.id_access_level_required
|
||||
, PC.active = t_C.active
|
||||
, PC.display_order = t_C.display_order
|
||||
, PC.id_change_set = v_id_change_set
|
||||
INSERT INTO Shop_Product_Category (
|
||||
code
|
||||
, name
|
||||
, description
|
||||
, id_access_level_required
|
||||
, active
|
||||
, display_order
|
||||
, created_by
|
||||
, created_on
|
||||
)
|
||||
SELECT
|
||||
-- t_C.id_category AS id_category
|
||||
t_C.code AS code
|
||||
, t_C.name AS name
|
||||
, t_C.description AS description
|
||||
, t_C.id_access_level_required AS id_access_level_required
|
||||
, t_C.active AS active
|
||||
, t_C.display_order AS display_order
|
||||
, a_id_user AS created_by
|
||||
, v_now AS created_on
|
||||
FROM tmp_Category t_C
|
||||
WHERE is_new = 1
|
||||
AND active = 1
|
||||
;
|
||||
END IF;
|
||||
|
||||
INSERT INTO Shop_Product_Category (
|
||||
code
|
||||
, name
|
||||
, description
|
||||
, id_access_level_required
|
||||
, active
|
||||
, display_order
|
||||
, created_by
|
||||
, created_on
|
||||
)
|
||||
SELECT
|
||||
-- t_C.id_category AS id_category
|
||||
t_C.code AS code
|
||||
, t_C.name AS name
|
||||
, t_C.description AS description
|
||||
, t_C.id_access_level_required AS id_access_level_required
|
||||
, t_C.active AS active
|
||||
, t_C.display_order AS display_order
|
||||
, a_id_user AS created_by
|
||||
, v_now AS created_on
|
||||
FROM tmp_Category t_C
|
||||
WHERE is_new = 1
|
||||
AND active = 1
|
||||
;
|
||||
|
||||
DELETE FROM Shop_Product_Category_Temp
|
||||
WHERE GUID = a_guid;
|
||||
|
||||
COMMIT;
|
||||
END IF;
|
||||
|
||||
DELETE FROM Shop_Product_Category_Temp
|
||||
WHERE GUID = a_guid;
|
||||
|
||||
SELECT * FROM tmp_Msg_Error;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Catgory;
|
||||
|
||||
@@ -192,7 +192,7 @@ BEGIN
|
||||
, t_C.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_shop_calc_user_clear_temp(a_guid);
|
||||
CALL p_shop_clear_calc_user(a_guid);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
@@ -9,16 +9,19 @@ DROP PROCEDURE IF EXISTS p_shop_save_product;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_save_product (
|
||||
IN a_comment VARCHAR(500),
|
||||
IN a_guid BINARY(36),
|
||||
IN a_id_user INT,
|
||||
IN a_comment VARCHAR(500)
|
||||
IN a_id_user INT,
|
||||
IN a_debug BIT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE v_code_type_error_bad_data VARCHAR(100);
|
||||
DECLARE v_id_access_level_edit INT;
|
||||
DECLARE v_id_type_error_bad_data INT;
|
||||
DECLARE v_id_permission_product INT;
|
||||
DECLARE v_ids_product_permission LONGTEXT;
|
||||
DECLARE v_id_change_set INT;
|
||||
DECLARE v_time_start TIMESTAMP(6);
|
||||
|
||||
DECLARE exit handler for SQLEXCEPTION
|
||||
BEGIN
|
||||
@@ -35,24 +38,44 @@ BEGIN
|
||||
-- Select the error information
|
||||
-- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message;
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid
|
||||
, id_type
|
||||
-- guid
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
a_guid
|
||||
, NULL
|
||||
-- a_guid
|
||||
(SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'MYSQL_ERROR' LIMIT 1)
|
||||
, @errno
|
||||
, @text
|
||||
, IFNULL(@text, 'NULL')
|
||||
;
|
||||
|
||||
SELECT *
|
||||
FROM tmp_Msg_Error t_ME
|
||||
INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type
|
||||
;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
|
||||
END;
|
||||
|
||||
SET v_code_type_error_bad_data := 'BAD_DATA';
|
||||
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' LIMIT 1);
|
||||
SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1);
|
||||
SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1);
|
||||
|
||||
SET a_guid := IFNULL(a_guid, UUID());
|
||||
SET a_debug := IFNULL(a_debug, 0);
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
SELECT
|
||||
v_code_type_error_bad_data
|
||||
, v_id_type_error_bad_data
|
||||
;
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_Product (
|
||||
id_category INT NOT NULL
|
||||
@@ -71,7 +94,7 @@ BEGIN
|
||||
|
||||
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 NOT NULL
|
||||
/*
|
||||
CONSTRAINT FK_tmp_Msg_Error_id_type
|
||||
@@ -98,79 +121,115 @@ BEGIN
|
||||
SELECT
|
||||
IFNULL(P_T.id_category, P.id_category) AS id_category
|
||||
, IFNULL(P_T.id_product, 0) AS id_product
|
||||
, IFNULL(PT.name, P.name) AS name
|
||||
, IFNULL(PT.has_variations, P.has_variations) AS has_variations
|
||||
, IFNULL(PT.id_access_level_required, P.id_access_level_required) AS id_access_level_required
|
||||
, IFNULL(P_T.name, P.name) AS name
|
||||
, IFNULL(P_T.has_variations, P.has_variations) AS has_variations
|
||||
, IFNULL(P_T.id_access_level_required, P.id_access_level_required) AS id_access_level_required
|
||||
, IFNULL(P_T.active, P.active) AS active
|
||||
, IFNULL(P_T.display_order, P.display_order) AS display_order
|
||||
, IFNULL(PT.name, IFNULL(P.name, IFNULL(P_T.id_product, '(No Product)'))) AS name_error
|
||||
, IFNULL(P_T.name, IFNULL(P.name, IFNULL(P_T.id_product, '(No Product)'))) AS name_error
|
||||
, CASE WHEN IFNULL(P_T.id_product, 0) < 1 THEN 1 ELSE 0 END AS is_new
|
||||
FROM Shop_Product_Tenp P_T
|
||||
LEFT JOIN Shop_Product P ON P_T.id_product = P.id_product
|
||||
FROM partsltd_prod.Shop_Product_Temp P_T
|
||||
LEFT JOIN partsltd_prod.Shop_Product P ON P_T.id_product = P.id_product
|
||||
;
|
||||
|
||||
-- Validation
|
||||
-- Missing mandatory fields
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
guid
|
||||
, id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
-- Missing mandatory fields
|
||||
-- id_category
|
||||
SELECT
|
||||
a_guid AS GUID
|
||||
, v_id_type_error_bad_data
|
||||
, v_code_error_bad_data
|
||||
, CONCAT('The following product(s) do not have a category: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', '))
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.id_category)
|
||||
UNION
|
||||
IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.id_category) LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
v_id_type_error_bad_data
|
||||
, v_code_type_error_bad_data
|
||||
, IFNULL(CONCAT('The following product(s) do not have a category: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL')
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.id_category)
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- name
|
||||
SELECT
|
||||
a_guid AS GUID
|
||||
, v_id_type_error_bad_data
|
||||
, v_code_error_bad_data
|
||||
, CONCAT('The following product(s) do not have a name: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', '))
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.name)
|
||||
UNION
|
||||
IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.name) LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
v_id_type_error_bad_data
|
||||
, v_code_type_error_bad_data
|
||||
, IFNULL(CONCAT('The following product(s) do not have a name: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL')
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.name)
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- has_variations
|
||||
SELECT
|
||||
a_guid AS GUID
|
||||
, v_id_type_error_bad_data
|
||||
, v_code_error_bad_data
|
||||
, CONCAT('The following product(s) do not have a has-variations setting: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', '))
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.has_variations)
|
||||
UNION
|
||||
IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.has_variations) LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
v_id_type_error_bad_data
|
||||
, v_code_type_error_bad_data
|
||||
, IFNULL(CONCAT('The following product(s) do not have a has-variations setting: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL')
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.has_variations)
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- id_access_level_required
|
||||
SELECT
|
||||
a_guid AS GUID
|
||||
, v_id_type_error_bad_data
|
||||
, v_code_error_bad_data
|
||||
, CONCAT('The following product(s) do not have a required access level ID: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', '))
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.id_access_level_required)
|
||||
UNION
|
||||
IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.id_access_level_required) LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
v_id_type_error_bad_data
|
||||
, v_code_type_error_bad_data
|
||||
, IFNULL(CONCAT('The following product(s) do not have a required access level ID: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL')
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.id_access_level_required)
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- display_order
|
||||
SELECT
|
||||
a_guid AS GUID
|
||||
, v_id_type_error_bad_data
|
||||
, v_code_error_bad_data
|
||||
, CONCAT('The following product(s) do not have a display order: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', '))
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.display_order)
|
||||
;
|
||||
IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.display_order) LIMIT 1) THEN
|
||||
INSERT INTO tmp_Msg_Error (
|
||||
id_type
|
||||
, code
|
||||
, msg
|
||||
)
|
||||
SELECT
|
||||
v_id_type_error_bad_data
|
||||
, v_code_type_error_bad_data
|
||||
, IFNULL(CONCAT('The following product(s) do not have a display order: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL')
|
||||
FROM tmp_Product t_P
|
||||
WHERE ISNULL(t_P.display_order)
|
||||
;
|
||||
END IF;
|
||||
|
||||
|
||||
-- Permissions
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN -- (SELECT * FROM tmp_Product WHERE is_new = 0 LIMIT 1) THEN
|
||||
SET v_ids_product_permission := (SELECT GROUP_CONCAT(item SEPARATOR ',') FROM tmp_Shop_Product WHERE is_new = 0);
|
||||
SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE is_new = 0);
|
||||
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_calc_user(a_guid, a_id_user, v_id_permission_product, v_ids_product_permission);
|
||||
CALL partsltd_prod.p_shop_calc_user(
|
||||
a_guid
|
||||
, a_id_user
|
||||
, FALSE -- get_inactive_users
|
||||
, v_id_permission_product
|
||||
, v_id_access_level_edit
|
||||
, v_ids_product_permission
|
||||
, 0 -- debug
|
||||
);
|
||||
|
||||
UPDATE tmp_Product t_P
|
||||
INNER JOIN Shop_Calc_User_Temp UE_T
|
||||
@@ -182,64 +241,72 @@ BEGIN
|
||||
, t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
CALL p_shop_calc_user_clear_temp(a_guid);
|
||||
CALL partsltd_prod.p_shop_clear_calc_user(
|
||||
a_guid
|
||||
, 0 -- debug
|
||||
);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
|
||||
-- Start the transaction
|
||||
START TRANSACTION;
|
||||
|
||||
-- Your transaction logic goes here
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
INSERT INTO Shop_Product_Change_Set ( comment )
|
||||
VALUES ( a_comment )
|
||||
;
|
||||
|
||||
SET v_id_change_set := LAST_INSERT_ID();
|
||||
|
||||
UPDATE Shop_Product P
|
||||
INNER JOIN tmp_Product t_P ON P.id_product = t_P.id_product
|
||||
SET
|
||||
P.id_category = t_P.id_category
|
||||
, P.name = t_P.name
|
||||
, P.has_variations = t_P.has_variations
|
||||
, P.id_access_level_required = t_P.id_access_level_required
|
||||
, P.display_order = t_P.display_order
|
||||
, P.id_change_set = v_id_change_set
|
||||
;
|
||||
END IF;
|
||||
|
||||
INSERT INTO Shop_Product (
|
||||
id_category
|
||||
, name
|
||||
, has_variations
|
||||
, id_access_level_required
|
||||
, display_order
|
||||
, created_by
|
||||
, created_on
|
||||
)
|
||||
SELECT
|
||||
t_P.id_category AS id_category
|
||||
, t_P.name AS name
|
||||
, t_P.has_variations AS has_variations
|
||||
, t_P.id_access_level_required AS id_access_level_required
|
||||
, t_P.display_order AS display_order
|
||||
, a_id_user AS created_by
|
||||
, v_now AS created_on
|
||||
FROM tmp_Product t_P
|
||||
WHERE is_new = 1
|
||||
;
|
||||
|
||||
-- If we reach here without error, commit the transaction
|
||||
IF NOT ISNULL(v_ids_product_permission) THEN
|
||||
INSERT INTO partsltd_prod.Shop_Product_Change_Set ( comment )
|
||||
VALUES ( a_comment )
|
||||
;
|
||||
|
||||
SET v_id_change_set := LAST_INSERT_ID();
|
||||
|
||||
UPDATE partsltd_prod.Shop_Product P
|
||||
INNER JOIN tmp_Product t_P ON P.id_product = t_P.id_product
|
||||
SET
|
||||
P.id_category = t_P.id_category
|
||||
, P.name = t_P.name
|
||||
, P.has_variations = t_P.has_variations
|
||||
, P.id_access_level_required = t_P.id_access_level_required
|
||||
, P.display_order = t_P.display_order
|
||||
, P.id_change_set = v_id_change_set
|
||||
;
|
||||
END IF;
|
||||
|
||||
INSERT INTO partsltd_prod.Shop_Product (
|
||||
id_category
|
||||
, name
|
||||
, has_variations
|
||||
, id_access_level_required
|
||||
, display_order
|
||||
, created_by
|
||||
, created_on
|
||||
)
|
||||
SELECT
|
||||
t_P.id_category AS id_category
|
||||
, t_P.name AS name
|
||||
, t_P.has_variations AS has_variations
|
||||
, t_P.id_access_level_required AS id_access_level_required
|
||||
, t_P.display_order AS display_order
|
||||
, a_id_user AS created_by
|
||||
, v_time_start AS created_on
|
||||
FROM tmp_Product t_P
|
||||
WHERE is_new = 1
|
||||
;
|
||||
|
||||
DELETE FROM partsltd_prod.Shop_Product_Category_Temp
|
||||
WHERE GUID = a_guid;
|
||||
COMMIT;
|
||||
END IF;
|
||||
|
||||
SELECT * FROM tmp_Msg_Error;
|
||||
SELECT *
|
||||
FROM tmp_Msg_Error t_ME
|
||||
INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type
|
||||
;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
|
||||
|
||||
IF a_debug = 1 THEN
|
||||
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
|
||||
END IF;
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
|
||||
78
static/MySQL/7203_p_shop_save_product_test.sql
Normal file
78
static/MySQL/7203_p_shop_save_product_test.sql
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
|
||||
-- Clear previous proc
|
||||
DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_test;
|
||||
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_save_product_test ()
|
||||
BEGIN
|
||||
|
||||
DECLARE v_guid BINARY(36);
|
||||
DECLARE v_time_start TIMESTAMP(6);
|
||||
|
||||
SET v_time_start := CURRENT_TIMESTAMP(6);
|
||||
SET v_guid := 'nips';
|
||||
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Temp
|
||||
;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
INSERT INTO partsltd_prod.Shop_Product_Temp (
|
||||
id_product
|
||||
, id_category
|
||||
, name
|
||||
, has_variations
|
||||
, id_access_level_required
|
||||
, display_order
|
||||
, active
|
||||
, guid
|
||||
)
|
||||
VALUES (
|
||||
4 -- id_product
|
||||
, 1 -- id_category
|
||||
, 'Laptops' -- name
|
||||
, 1 -- has_variations
|
||||
, 2 -- id_access_level_required
|
||||
, 2 -- display_order
|
||||
, 1 -- active
|
||||
, v_guid
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Temp
|
||||
WHERE GUID = v_guid
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_shop_save_product (
|
||||
'Test save product' -- comment
|
||||
, v_guid -- guid
|
||||
, 1 -- id_user
|
||||
, 1 -- debug
|
||||
);
|
||||
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product
|
||||
;
|
||||
SELECT *
|
||||
FROM partsltd_prod.Shop_Product_Temp
|
||||
;
|
||||
|
||||
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
|
||||
END //
|
||||
DELIMITER ;;
|
||||
|
||||
CALL partsltd_prod.p_shop_save_product_test ();
|
||||
|
||||
DELETE FROM partsltd_prod.Shop_Product_Temp;
|
||||
/*
|
||||
|
||||
DROP TABLE IF EXISTS tmp_Msg_Error;
|
||||
*/
|
||||
@@ -1,605 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
-- 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;
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@@ -6,9 +6,9 @@ DROP PROCEDURE IF EXISTS p_shop_save_product_permutation;
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE p_shop_save_product_permutation (
|
||||
IN a_id_user INT,
|
||||
IN a_comment VARCHAR(500),
|
||||
IN a_guid BINARY(36)
|
||||
IN a_guid BINARY(36),
|
||||
IN a_id_user INT
|
||||
)
|
||||
BEGIN
|
||||
|
||||
|
||||
@@ -26,14 +26,14 @@ BEGIN
|
||||
DECLARE v_id_access_level_view INT;
|
||||
DECLARE v_time_start TIMESTAMP(6);
|
||||
DECLARE v_id_minimum INT;
|
||||
DECLARE v_code_error_data VARCHAR(50);
|
||||
DECLARE v_id_type_error_data INT;
|
||||
DECLARE v_code_error_bad_data VARCHAR(50);
|
||||
DECLARE v_id_type_error_bad_data INT;
|
||||
|
||||
SET v_time_start := CURRENT_TIMESTAMP(6);
|
||||
SET v_guid := UUID();
|
||||
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1);
|
||||
SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1);
|
||||
SET v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1);
|
||||
SET v_code_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1);
|
||||
SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_bad_data LIMIT 1);
|
||||
|
||||
-- Argument validation + default values
|
||||
SET a_id_user = IFNULL(a_id_user, 0);
|
||||
@@ -282,8 +282,8 @@ BEGIN
|
||||
)
|
||||
VALUES (
|
||||
-- v_guid,
|
||||
v_id_type_error_data,
|
||||
v_code_error_data,
|
||||
v_id_type_error_bad_data,
|
||||
v_code_error_bad_data,
|
||||
CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_variation LIMIT 1))
|
||||
)
|
||||
;
|
||||
|
||||
@@ -609,7 +609,7 @@ BEGIN
|
||||
)
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM partsltd_prod.Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -184,7 +184,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
|
||||
@@ -615,7 +615,7 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -528,7 +528,7 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -180,7 +180,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = a_guid;
|
||||
|
||||
@@ -627,7 +627,7 @@ BEGIN
|
||||
t_P.can_admin = UE_T.can_admin
|
||||
;
|
||||
|
||||
# CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
# CALL p_shop_clear_calc_user(v_guid);
|
||||
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -33,9 +33,10 @@ INSERT INTO Shop_Msg_Error_Type (
|
||||
code, name, description
|
||||
)
|
||||
VALUES
|
||||
('BAD_DATA', 'Invalid data', 'Rubbish data'),
|
||||
('NO_PERMISSION', 'No permission', 'Not authorised'),
|
||||
('PRODUCT_AVAILABILITY', 'Product not available', 'Product not available')
|
||||
('BAD_DATA', 'Invalid data', 'Rubbish data')
|
||||
, ('NO_PERMISSION', 'No permission', 'Not authorised')
|
||||
, ('PRODUCT_AVAILABILITY', 'Product not available', 'Product not available')
|
||||
, ('MYSQL_ERROR', 'MySQL error', 'MySQL execution error.')
|
||||
;
|
||||
|
||||
# File Types
|
||||
|
||||
@@ -6982,7 +6982,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid;
|
||||
@@ -7878,7 +7878,7 @@ BEGIN
|
||||
*/
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid;
|
||||
@@ -10368,7 +10368,7 @@ BEGIN
|
||||
OR t_P.can_view = FALSE
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
@@ -12527,7 +12527,7 @@ BEGIN
|
||||
AND UE_T.GUID = v_guid
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
@@ -13156,7 +13156,7 @@ BEGIN
|
||||
AND UE_T.GUID = v_guid
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
@@ -14099,7 +14099,7 @@ BEGIN
|
||||
AND UE_T.GUID = v_guid
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -179,7 +179,7 @@ BEGIN
|
||||
tP.can_edit = TP.can_edit,
|
||||
tP.can_admin = TP.can_admin;
|
||||
|
||||
CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
END IF;
|
||||
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ BEGIN
|
||||
;
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid;
|
||||
|
||||
@@ -199,7 +199,7 @@ BEGIN
|
||||
*/
|
||||
END IF;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid_permission);
|
||||
-- CALL p_shop_clear_calc_user(v_guid_permission);
|
||||
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid;
|
||||
|
||||
@@ -822,7 +822,7 @@ BEGIN
|
||||
OR t_P.can_view = FALSE
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -534,7 +534,7 @@ BEGIN
|
||||
AND UE_T.GUID = v_guid
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -454,7 +454,7 @@ BEGIN
|
||||
AND UE_T.GUID = v_guid
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
@@ -547,7 +547,7 @@ BEGIN
|
||||
AND UE_T.GUID = v_guid
|
||||
;
|
||||
|
||||
-- CALL p_shop_calc_user_clear_temp(v_guid);
|
||||
-- CALL p_shop_clear_calc_user(v_guid);
|
||||
-- DROP TABLE IF EXISTS Shop_Calc_User_Temp;
|
||||
DELETE FROM Shop_Calc_User_Temp
|
||||
WHERE GUID = v_guid
|
||||
|
||||
76
static/css/pages/store/products.css
Normal file
76
static/css/pages/store/products.css
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
#formFilters {
|
||||
width: 50vh;
|
||||
}
|
||||
|
||||
#formFilters .container {
|
||||
max-width: fit-content;
|
||||
}
|
||||
|
||||
#formFilters .container-input.filter.is_not_empty {
|
||||
width: 10vh;
|
||||
}
|
||||
|
||||
#formFilters .container-input.filter.active {
|
||||
width: 8vh;
|
||||
}
|
||||
|
||||
/*
|
||||
#tableMain {
|
||||
max-width: min(calc(1vh * 79), calc(1vw * 90));
|
||||
}
|
||||
*/
|
||||
|
||||
#tableMain tbody tr td.display_order, #tableMain thead tr th.display_order {
|
||||
width: 5vh;
|
||||
min-width: 5vh;
|
||||
}
|
||||
#tableMain tbody tr td.product_category, #tableMain thead tr th.product_category {
|
||||
width: 15vh;
|
||||
min-width: 15vh;
|
||||
}
|
||||
#tableMain tbody tr td.name, #tableMain thead tr th.name {
|
||||
width: 15vh;
|
||||
min-width: 15vh;
|
||||
}
|
||||
#tableMain thead tr th.has_variations, #tableMain tbody tr td.has_variations {
|
||||
width: 5vh;
|
||||
min-width: 5vh;
|
||||
}
|
||||
#tableMain tbody tr td.access_level, #tableMain thead tr th.access_level {
|
||||
width: 7vh;
|
||||
min-width: 7vh;
|
||||
}
|
||||
#tableMain tbody tr td.active, #tableMain thead tr th.active {
|
||||
width: 5vh;
|
||||
min-width: 5vh;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
td > input, td > select, td > textarea, .container-input > input, .container-input > select, .container-input > textarea {
|
||||
border: 2px solid var(--c_purple);
|
||||
border-radius: 0.5vh;
|
||||
}
|
||||
|
||||
#tableMain tbody tr td button {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#tableMain tbody tr td table thead tr th.id_variation_type, #tableMain tbody tr td table tbody tr td.id_variation_type, #tableMain tbody tr td table thead tr th.id_variation, #tableMain tbody tr td table tbody tr td.id_variation {
|
||||
width: 47.5%;
|
||||
}
|
||||
|
||||
2
static/dist/js/main.bundle.js
vendored
2
static/dist/js/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -95,6 +95,21 @@ export default class API {
|
||||
return await API.request(hashSaveStoreProductCategory, 'POST', dataRequest);
|
||||
}
|
||||
|
||||
// products
|
||||
static async getProducts() {
|
||||
return await API.request(hashGetStoreProduct);
|
||||
}
|
||||
static async getProductsByFilters(filtersJson) {
|
||||
API.goToHash(hashPageStoreProducts, filtersJson);
|
||||
}
|
||||
static async saveProducts(products, formFilters, comment) {
|
||||
let dataRequest = {};
|
||||
dataRequest[flagFormFilters] = DOM.convertForm2JSON(formFilters);
|
||||
dataRequest[flagProduct] = products;
|
||||
dataRequest[flagComment] = comment;
|
||||
return await API.request(hashSaveStoreProduct, 'POST', dataRequest);
|
||||
}
|
||||
|
||||
// product permutations
|
||||
static async getProductPermutations() {
|
||||
return await API.request(hashGetStoreProductPermutation);
|
||||
|
||||
@@ -118,20 +118,36 @@ export default class DOM {
|
||||
}
|
||||
static getElementAttributeValueCurrent(element) {
|
||||
return element.getAttribute(attrValueCurrent);
|
||||
if (!Validation.isEmpty(value) && element.type === "checkbox") {
|
||||
value = (value === 'true');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
static getElementAttributeValuePrevious(element) {
|
||||
return element.getAttribute(attrValuePrevious);
|
||||
if (!Validation.isEmpty(value) && element.type === "checkbox") {
|
||||
value = (value === 'true');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/* base_table.handleChangeElementCellTable
|
||||
static updateAndCheckIsTableElementDirty(element) {
|
||||
let wasDirty = DOM.isElementDirty(element);
|
||||
let row = DOM.getRowFromElement(element);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
let isDirty = DOM.updateAndCheckIsElementDirty(element);
|
||||
let cell = DOM.getCellFromElement(element);
|
||||
if (isDirty) {
|
||||
cell.classList.add(flagDirty);
|
||||
} else {
|
||||
cell.classList.remove(flagDirty);
|
||||
console.log({element, row, cell, isDirty, wasDirty});
|
||||
if (isDirty != wasDirty) {
|
||||
DOM.handleDirtyElement(cell, isDirty);
|
||||
let isDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
console.log({isDirtyRow, wasDirtyRow});
|
||||
if (isDirtyRow != wasDirtyRow) {
|
||||
DOM.handleDirtyElement(row, isDirtyRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
static updateElement(id, data) {
|
||||
const element = document.getElementById(id);
|
||||
|
||||
@@ -93,6 +93,9 @@ export default class TableBasePage extends BasePage {
|
||||
}
|
||||
return isDirty;
|
||||
}
|
||||
hookupFilterIsNotEmpty() {
|
||||
this.hookupFilter(flagIsNotEmpty);
|
||||
}
|
||||
hookupButtonApplyFilters() {
|
||||
this.hookupEventHandler("click", idButtonApplyFilters, (event, button) => {
|
||||
event.stopPropagation();
|
||||
@@ -275,35 +278,27 @@ export default class TableBasePage extends BasePage {
|
||||
this.hookupChangeHandlerTableCells(selectorDisplayOrder);
|
||||
}
|
||||
hookupChangeHandlerTableCells(inputSelector, handler = (event, element) => { this.handleChangeElementCellTable(event, element); }) {
|
||||
/*
|
||||
Events.initialiseEventHandler(inputSelector, flagInitialised, (input) => {
|
||||
input.addEventListener("change", (event) => {
|
||||
handler(event, input);
|
||||
});
|
||||
this.handleChangeElementCellTable(null, input);
|
||||
});
|
||||
*/
|
||||
this.hookupEventHandler("change", inputSelector, handler);
|
||||
// this.hookupEventHandler("change", inputSelector, handler);
|
||||
}
|
||||
handleChangeElementCellTable(event, element) {
|
||||
let row = DOM.getRowFromElement(element);
|
||||
let td = DOM.getCellFromElement(element);
|
||||
console.log("td: ", td);
|
||||
let wasDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
let wasDirtyElement = element.classList.contains(flagDirty);
|
||||
let isDirtyElement = DOM.updateAndCheckIsElementDirty(element);
|
||||
console.log("isDirtyElement: ", isDirtyElement);
|
||||
console.log("wasDirtyElement: ", wasDirtyElement);
|
||||
if (isDirtyElement != wasDirtyElement) {
|
||||
DOM.handleDirtyElement(td, isDirtyElement);
|
||||
let isNowDirtyRow = DOM.hasDirtyChildrenContainer(row);
|
||||
console.log("isNowDirtyRow: ", isNowDirtyRow);
|
||||
console.log("wasDirtyRow: ", wasDirtyRow);
|
||||
if (isNowDirtyRow != wasDirtyRow) {
|
||||
DOM.handleDirtyElement(row, isNowDirtyRow);
|
||||
let rows = this.getTableRecords(true);
|
||||
let existsDirtyRecord = rows.length > 0;
|
||||
console.log("dirty records:", rows);
|
||||
console.log("existsDirtyRecord:", existsDirtyRecord);
|
||||
this.toggleShowButtonsSaveCancel(existsDirtyRecord);
|
||||
}
|
||||
}
|
||||
|
||||
150
static/js/pages/store/products.js
Normal file
150
static/js/pages/store/products.js
Normal file
@@ -0,0 +1,150 @@
|
||||
|
||||
import Events from "../../lib/events.js";
|
||||
import TableBasePage from "../base_table.js";
|
||||
import API from "../../api.js";
|
||||
import DOM from "../../dom.js";
|
||||
import StoreTableMixinPage from "./mixin_table.js";
|
||||
import Utils from "../../lib/utils.js";
|
||||
|
||||
export default class PageStoreProducts extends TableBasePage {
|
||||
static hash = hashPageStoreProducts;
|
||||
callFilterTableContent = API.getProductsByFilters;
|
||||
callSaveTableContent = API.saveProducts;
|
||||
|
||||
constructor(router) {
|
||||
super(router);
|
||||
this.storeMixin = new StoreTableMixinPage(this);
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.sharedInitialize();
|
||||
}
|
||||
|
||||
hookupFilters() {
|
||||
this.sharedHookupFilters();
|
||||
this.hookupFilterProductCategory();
|
||||
this.hookupFilterIsNotEmpty();
|
||||
this.hookupFilterActive();
|
||||
}
|
||||
hookupFilterProductCategory() {
|
||||
this.hookupFilter(flagProductCategory);
|
||||
}
|
||||
|
||||
loadRowTable(rowJson) {
|
||||
return;
|
||||
if (rowJson == null) return;
|
||||
let row = _rowBlank.cloneNode(true);
|
||||
row.classList.remove(flagRowNew);
|
||||
row.classList.remove(flagInitialised);
|
||||
row.querySelectorAll('.' + flagInitialised).forEach(function(element) {
|
||||
element.classList.remove(flagInitialised);
|
||||
});
|
||||
console.log("applying data row: ", rowJson);
|
||||
let sliderDisplayOrder = row.querySelector('td.' + flagDisplayOrder + ' .' + flagSlider);
|
||||
let tdProductCategory = row.querySelector('td.' + flagProductCategory);
|
||||
let divProductCategory = tdProductCategory.querySelector('div.' + flagProductCategory);
|
||||
let textareaName = row.querySelector('td.' + flagName + ' textarea');
|
||||
let tdAccessLevel = row.querySelector('td.' + flagAccessLevel);
|
||||
let divAccessLevel = tdAccessLevel.querySelector('div.' + flagAccessLevel);
|
||||
let inputActive = row.querySelector('td.' + flagActive + ' input[type="checkbox"]');
|
||||
|
||||
DOM.setElementValuesCurrentAndPrevious(sliderDisplayOrder, rowJson[flagDisplayOrder]);
|
||||
DOM.setElementValuesCurrentAndPrevious(textareaCode, rowJson[flagCode]);
|
||||
DOM.setElementValuesCurrentAndPrevious(textareaName, rowJson[flagName]);
|
||||
DOM.setElementValuesCurrentAndPrevious(textareaDescription, rowJson[flagDescription]);
|
||||
tdAccessLevel.setAttribute(attrIdAccessLevel, rowJson[attrIdAccessLevel]);
|
||||
tdAccessLevel.setAttribute(flagAccessLevelRequired, rowJson[flagAccessLevelRequired]);
|
||||
divAccessLevel.setAttribute(attrIdAccessLevel, rowJson[attrIdAccessLevel]);
|
||||
DOM.setElementValuesCurrentAndPrevious(divAccessLevel, rowJson[attrIdAccessLevel]);
|
||||
divAccessLevel.textContent = rowJson[flagAccessLevelRequired];
|
||||
DOM.setElementValuesCurrentAndPrevious(inputActive, rowJson[flagActive]);
|
||||
row.setAttribute(rowJson[flagKeyPrimary], rowJson[rowJson[flagKeyPrimary]]);
|
||||
|
||||
let table = this.getTableMain();
|
||||
let bodyTable = table.querySelector('tbody');
|
||||
bodyTable.appendChild(row);
|
||||
}
|
||||
getJsonRow(row) {
|
||||
if (row == null) return;
|
||||
let sliderDisplayOrder = row.querySelector('td.' + flagDisplayOrder + ' .' + flagSlider);
|
||||
let tdProductCategory = row.querySelector('td.' + flagProductCategory);
|
||||
let textareaName = row.querySelector('td.' + flagName + ' textarea');
|
||||
// let tdProductVariations = row.querySelector('td.' + flagProductVariations);
|
||||
let inputHasVariations = row.querySelector('td.' + flagHasVariations + ' input[type="checkbox"]');
|
||||
let tdAccessLevel = row.querySelector('td.' + flagAccessLevel);
|
||||
let inputActive = row.querySelector('td.' + flagActive + ' input[type="checkbox"]');
|
||||
|
||||
let jsonProduct = {};
|
||||
jsonProduct[attrIdProduct] = row.getAttribute(attrIdProduct);
|
||||
jsonProduct[attrIdProductCategory] = DOM.getElementAttributeValueCurrent(tdProductCategory);
|
||||
jsonProduct[flagName] = DOM.getElementAttributeValueCurrent(textareaName);
|
||||
// jsonRow[flagProductVariations] = DOM.getElementAttributeValueCurrent(tdProductVariations);
|
||||
// jsonRow[flagHasVariations] = jsonRow[flagProductVariations] != '';
|
||||
jsonProduct[flagHasVariations] = DOM.getElementAttributeValueCurrent(inputHasVariations);
|
||||
// jsonProduct[flagAccessLevelRequired] = tdAccessLevel.getAttribute(flagAccessLevelRequired);
|
||||
jsonProduct[attrIdAccessLevel] = DOM.getElementAttributeValueCurrent(tdAccessLevel);
|
||||
jsonProduct[flagActive] = DOM.getElementAttributeValueCurrent(inputActive);
|
||||
jsonProduct[flagDisplayOrder] = DOM.getElementAttributeValueCurrent(sliderDisplayOrder);
|
||||
return jsonProduct;
|
||||
}
|
||||
initialiseRowNew(row) {
|
||||
if (row == null) return;
|
||||
let slidersDisplayOrder = document.querySelectorAll('td.' + flagDisplayOrder + ' input.' + flagSlider);
|
||||
let maxDisplayOrder = 0;
|
||||
slidersDisplayOrder.forEach((slider) => {
|
||||
maxDisplayOrder = Math.max(maxDisplayOrder, parseFloat(DOM.getElementValueCurrent(slider)));
|
||||
});
|
||||
let sliderDisplayOrder = row.querySelector('td.' + flagDisplayOrder + ' .' + flagSlider);
|
||||
DOM.setElementValuesCurrentAndPrevious(sliderDisplayOrder, maxDisplayOrder + 1);
|
||||
}
|
||||
|
||||
hookupTableMain() {
|
||||
super.hookupTableMain();
|
||||
this.hookupSlidersDisplayOrderTable();
|
||||
this.hookupTdsProductCategory();
|
||||
this.hookupTextareasNameTable();
|
||||
this.hookupInputsHasVariationsTable();
|
||||
this.hookupTdsAccessLevel();
|
||||
this.hookupInputsActiveTable();
|
||||
}
|
||||
hookupTdsProductCategory() {
|
||||
let cellSelector = idTableMain + ' tbody td.' + flagProductCategory;
|
||||
this.hookupTableCellDdlPreviews(cellSelector, Utils.getListFromDict(productCategories));
|
||||
}
|
||||
hookupInputsHasVariationsTable() {
|
||||
let cellSelector = idTableMain + ' tbody td.' + flagHasVariations + ' input[type="checkbox"]';
|
||||
this.hookupChangeHandlerTableCells(cellSelector);
|
||||
}
|
||||
|
||||
/*
|
||||
isDirtyRow(row) {
|
||||
if (row == null) return false;
|
||||
console.log("Product Product isDirtyRow");
|
||||
console.log("row: ", row);
|
||||
let sliderDisplayOrder = row.querySelector('td.' + flagDisplayOrder);
|
||||
let inputCode = row.querySelector('td.' + flagCode + ' textarea');
|
||||
let inputName = row.querySelector('td.' + flagName + ' textarea');
|
||||
let inputDescription = row.querySelector('td.' + flagDescription + ' textarea');
|
||||
let tdAccessLevel = row.querySelector('td.' + flagAccessLevel);
|
||||
let inputActive = row.querySelector('td.' + flagActive + ' input[type="checkbox"]');
|
||||
let isDirty = sliderDisplayOrder.classList.contains(flagDirty) || inputCode.classList.contains(flagDirty) || inputName.classList.contains(flagDirty) ||
|
||||
inputDescription.classList.contains(flagDirty) || tdAccessLevel.classList.contains(flagDirty) || inputActive.classList.contains(flagDirty);
|
||||
DOM.handleDirtyElement(row, isDirty);
|
||||
return isDirty;
|
||||
}
|
||||
*/
|
||||
|
||||
leave() {
|
||||
super.leave();
|
||||
}
|
||||
|
||||
/*
|
||||
getFiltersDefaults() {
|
||||
filters = {};
|
||||
filters.flagIsNotEmpty = true;
|
||||
filters.flagActive = true;
|
||||
return filters;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import PageStoreHome from './pages/store/home.js';
|
||||
import PageStoreProductCategories from './pages/store/product_categories.js';
|
||||
import PageStoreProductPermutations from './pages/store/product_permutations.js';
|
||||
// import PageStoreProductPrices from './pages/store/product_prices.js';
|
||||
// import PageStoreProducts from './pages/store/products.js';
|
||||
import PageStoreProducts from './pages/store/products.js';
|
||||
// import PageStoreProductVariations from './pages/store/product_variations.js';
|
||||
import PageStoreStockItems from './pages/store/stock_items.js';
|
||||
// User
|
||||
@@ -80,7 +80,7 @@ export default class Router {
|
||||
this.pages[hashPageStoreProductCategories] = { name: 'PageStoreProductCategories', module: PageStoreProductCategories }; // pathModule: './pages/store/product_categories.js' };
|
||||
this.pages[hashPageStoreProductPermutations] = { name: 'PageStoreProductPermutations', module: PageStoreProductPermutations }; // pathModule: './pages/store/product_permutations.js' };
|
||||
// this.pages[hashPageStoreProductPrices] = { name: 'PageStoreProductPrices', module: PageStoreProductPrices }; // pathModule: './pages/store/product_prices.js' };
|
||||
// this.pages[hashPageStoreProducts] = { name: 'PageStoreProducts', module: PageStoreProducts }; // pathModule: './pages/store/products.js' };
|
||||
this.pages[hashPageStoreProducts] = { name: 'PageStoreProducts', module: PageStoreProducts }; // pathModule: './pages/store/products.js' };
|
||||
// this.pages[hashPageStoreProductVariations] = { name: 'PageStoreProductVariations', module: PageStoreProductVariations }; // pathModule: './pages/store/product_variations.js' };
|
||||
this.pages[hashPageStoreStockItems] = { name: 'PageStoreStockItems', module: PageStoreStockItems };
|
||||
// User
|
||||
@@ -106,6 +106,7 @@ export default class Router {
|
||||
// this.routes[hashPageStoreProductPrices] = (isPopState = false) => this.navigateToHash(hashPageStoreProductPrices, isPopState);
|
||||
this.routes[hashPageStoreProducts] = (isPopState = false) => this.navigateToHash(hashPageStoreProducts, isPopState);
|
||||
// this.routes[hashPageStoreProductVariations] = (isPopState = false) => this.navigateToHash(hashPageStoreProductVariations, isPopState);
|
||||
this.routes[hashPageStoreStockItems] = (isPopState = false) => this.navigateToHash(hashPageStoreStockItems, isPopState);
|
||||
// User
|
||||
// this.routes[hashPageUserLogin] = (isPopState = false) => this.navigateToHash(hashPageUserLogin, isPopState);
|
||||
// this.routes[hashPageUserLogout] = (isPopState = false) => this.navigateToHash(hashPageUserLogout, isPopState);
|
||||
|
||||
Reference in New Issue
Block a user