feat(UI): Stock Items page added with getting, filtering, and saving data.

This commit is contained in:
2024-10-13 19:40:25 +01:00
parent 818d049702
commit f6a6966ce4
183 changed files with 5747 additions and 8607 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,8 @@ DROP TABLE IF EXISTS tmp_Shop_Customer_Sale_Order;
# Delete old tables
DROP TABLE IF EXISTS Split_Temp;
DROP TABLE IF EXISTS Split_Key_Value_Pair_Csv_Temp;
DROP TABLE IF EXISTS Split_Key_Value_Pair_Temp;
DROP TABLE IF EXISTS Shop_User_Eval_Temp;
DROP TABLE IF EXISTS Shop_Calc_User_Temp;
@@ -87,8 +89,8 @@ DROP TABLE IF EXISTS Shop_User_Order_Status;
DROP TABLE IF EXISTS Shop_User_Basket_Audit;
DROP TABLE IF EXISTS Shop_User_Basket;
DROP TABLE IF EXISTS Shop_Address_Audit;
DROP TABLE IF EXISTS Shop_Address;
DROP TABLE IF EXISTS Shop_User_Address_Audit;
DROP TABLE IF EXISTS Shop_User_Address;
DROP TABLE IF EXISTS Shop_User_Role_Link_Audit;
DROP TABLE IF EXISTS Shop_User_Role_Link;
@@ -190,6 +192,9 @@ DROP TABLE IF EXISTS Shop_Plant_Temp;
DROP TABLE IF EXISTS Shop_Plant_Audit;
DROP TABLE IF EXISTS Shop_Plant;
DROP TABLE IF EXISTS Shop_Address_Audit;
DROP TABLE IF EXISTS Shop_Address;
DROP TABLE IF EXISTS Shop_Delivery_Region_Branch_Audit;
DROP TABLE IF EXISTS Shop_Delivery_Region_Branch;
DROP TABLE IF EXISTS Shop_Region_Branch_Temp;
@@ -232,6 +237,9 @@ DROP TABLE IF EXISTS Shop_Product_Change_Set;
-- Procedures
DROP PROCEDURE IF EXISTS p_split;
DROP PROCEDURE IF EXISTS p_clear_split_temp;
DROP PROCEDURE IF EXISTS p_split_key_value_pair_csv;
DROP PROCEDURE IF EXISTS p_clear_split_key_value_csv_temp;
DROP PROCEDURE IF EXISTS p_clear_split_key_value_pair_csv_temp;
DROP PROCEDURE IF EXISTS p_debug_timing_reporting;
DROP PROCEDURE IF EXISTS p_validate_guid;
@@ -248,12 +256,15 @@ DROP PROCEDURE IF EXISTS p_shop_get_many_access_level;
DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement;
DROP PROCEDURE IF EXISTS p_shop_get_many_region;
DROP PROCEDURE IF EXISTS p_shop_get_many_plant;
DROP PROCEDURE IF EXISTS p_shop_get_many_storage_location;
DROP PROCEDURE IF EXISTS p_shop_get_many_currency;
DROP PROCEDURE IF EXISTS p_shop_save_category;
DROP PROCEDURE IF EXISTS p_shop_save_product_category;
DROP PROCEDURE IF EXISTS p_shop_save_product_category_test;
DROP PROCEDURE IF EXISTS p_shop_save_product;
DROP PROCEDURE IF EXISTS p_shop_save_product_test;
DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation;
DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation;
DROP PROCEDURE IF EXISTS p_shop_get_many_product;
@@ -261,6 +272,9 @@ DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new;
DROP PROCEDURE IF EXISTS p_shop_save_permutation;
DROP PROCEDURE IF EXISTS p_shop_save_product_permutation;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation;
DROP FUNCTION IF EXISTS fn_shop_get_id_product_permutation_from_variation_csv_list;
DROP PROCEDURE IF EXISTS p_shop_save_stock_item;
DROP PROCEDURE IF EXISTS p_shop_save_stock_item_test;
DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option;

View File

@@ -0,0 +1,13 @@
# Split Key Value Pair CSV 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_Key_Value_Pair_Csv_Temp';
CREATE TABLE Split_Key_Value_Pair_Csv_Temp (
guid BINARY(36) NOT NULL
, id INT NOT NULL
, key_column VARCHAR(4000) NULL
, value_column VARCHAR(4000) NULL
);

View File

@@ -1,8 +1,6 @@
# Regions
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region';
CREATE TABLE IF NOT EXISTS Shop_Region (

View File

@@ -0,0 +1,22 @@
# Addresses
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address';
CREATE TABLE Shop_Address (
id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_region INT NOT NULL,
postcode VARCHAR(20) NOT NULL,
address_line_1 VARCHAR(256) NOT NULL,
address_line_2 VARCHAR(256) NOT NULL,
city VARCHAR(256) NOT NULL,
county VARCHAR(256) NOT NULL,
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Address_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_User_Change_Set(id_change_set)
);

View File

@@ -1,8 +1,6 @@
# Plant
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant';
CREATE TABLE IF NOT EXISTS Shop_Plant (
@@ -10,6 +8,9 @@ CREATE TABLE IF NOT EXISTS Shop_Plant (
code VARCHAR(50) NOT NULL,
name VARCHAR(500) NOT NULL,
id_address INT NOT NULL,
CONSTRAINT FK_Shop_Plant_id_address
FOREIGN KEY (id_address)
REFERENCES Shop_Address(id_address),
id_user_manager INT NOT NULL,
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,

View File

@@ -6,10 +6,11 @@
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant_Temp';
CREATE TABLE IF NOT EXISTS Shop_Plant_Temp (
id_plant INT NOT NULL PRIMARY KEY,
code VARCHAR(50) NOT NULL,
name VARCHAR(500) NOT NULL,
id_address INT NOT NULL,
id_user_manager INT NOT NULL,
active BIT NOT NULL DEFAULT 1
id_plant INT NOT NULL PRIMARY KEY
, code VARCHAR(50) NOT NULL
, name VARCHAR(500) NOT NULL
, id_address INT NOT NULL
, id_user_manager INT NOT NULL
, active BIT NOT NULL DEFAULT 1
, guid BINARY(36) NOT NULL
);

View File

@@ -1,7 +1,7 @@
# Stock Stock Item
-- DROP TABLE IF EXISTS Shop_Stock_Item;
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item';
@@ -11,8 +11,8 @@ CREATE TABLE IF NOT EXISTS Shop_Stock_Item (
CONSTRAINT FK_Shop_Stock_Item_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation),
date_purchased TIMESTAMP NOT NULL,
date_received TIMESTAMP NULL,
date_purchased DATETIME NOT NULL,
date_received DATETIME NULL,
id_location_storage INT NOT NULL,
CONSTRAINT FK_Shop_Stock_Item_id_location_storage
FOREIGN KEY (id_location_storage)
@@ -21,15 +21,15 @@ CREATE TABLE IF NOT EXISTS Shop_Stock_Item (
CONSTRAINT FK_Shop_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,
cost_local_VAT_incl FLOAT NULL,
cost_local_VAT_excl FLOAT NULL,
is_sealed BIT NOT NULL DEFAULT 1,
date_unsealed TIMESTAMP NULL,
date_expiration TIMESTAMP NOT NULL,
date_unsealed DATETIME NULL,
date_expiration DATETIME NOT NULL,
is_consumed BIT NOT NULL DEFAULT 0,
date_consumed TIMESTAMP NULL,
date_consumed DATETIME NULL,
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,
created_on DATETIME,
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Stock_Item_id_change_set

View File

@@ -1,22 +1,27 @@
# Stock Stock Item Temp
DROP TABLE IF EXISTS Shop_Stock_Item_Temp;
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item_Temp';
CREATE TABLE IF NOT EXISTS Shop_Stock_Item_Temp (
id_stock INT NOT NULL PRIMARY KEY,
id_permutation INT NOT NULL,
date_purchased TIMESTAMP NOT NULL,
id_location_storage INT NOT NULL,
id_currency INT NOT NULL,
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 NULL,
is_consumed BIT NOT NULL DEFAULT 0,
date_consumed TIMESTAMP NULL,
active BIT NOT NULL DEFAULT 1
id_stock INT NULL
-- , id_category INT NULL
, id_product INT NOT NULL
, id_permutation INT NULL
, id_pairs_variations VARCHAR(4000) NULL
, date_purchased DATETIME NOT NULL
, date_received DATETIME NULL
, id_location_storage INT NOT NULL
, id_currency_cost INT NOT NULL
, cost_local_VAT_incl FLOAT NOT NULL
, cost_local_VAT_excl FLOAT NOT NULL
, is_sealed BIT NOT NULL
, date_unsealed DATETIME NULL
, date_expiration DATETIME NULL
, is_consumed BIT NOT NULL
, date_consumed DATETIME NULL
, active BIT NOT NULL
, guid BINARY(36) NOT NULL
);

View File

@@ -1,12 +1,10 @@
# Addresses
# User Addresses
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Address';
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address';
CREATE TABLE Shop_Address (
id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
CREATE TABLE Shop_User_Address (
id_user_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_user INT NOT NULL,
CONSTRAINT FK_Shop_Address_id_user
FOREIGN KEY (id_user)
@@ -17,15 +15,15 @@ CREATE TABLE Shop_Address (
name_full VARCHAR(255) NOT NULL,
phone_number VARCHAR(20) NOT NULL,
postcode VARCHAR(20) NOT NULL,
address_line_1 VARCHAR(100) NOT NULL,
address_line_2 VARCHAR(100) NOT NULL,
city VARCHAR(50) NOT NULL,
county VARCHAR(100) NOT NULL,
address_line_1 VARCHAR(256) NOT NULL,
address_line_2 VARCHAR(256) NOT NULL,
city VARCHAR(256) NOT NULL,
county VARCHAR(256) NOT NULL,
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Address_id_change_set
CONSTRAINT FK_Shop_User_Address_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_User_Change_Set(id_change_set)
);

View File

@@ -0,0 +1,21 @@
# Address Audits
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Address_Audit';
CREATE TABLE IF NOT EXISTS Shop_User_Address_Audit (
id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_user_address INT NOT NULL,
CONSTRAINT FK_Shop_User_Address_Audit_id_address
FOREIGN KEY (id_user_address)
REFERENCES Shop_User_Address(id_user_address)
ON UPDATE RESTRICT,
name_field VARCHAR(50),
value_prev VARCHAR(500),
value_new VARCHAR(500),
id_change_set INT NOT NULL,
CONSTRAINT FK_Shop_User_Address_Audit_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_User_Change_Set(id_change_set)
ON UPDATE RESTRICT
);

View File

@@ -39,14 +39,6 @@ BEGIN
SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set
WHERE NOT OLD.id_region <=> NEW.id_region
UNION
# Changed name_full
SELECT NEW.id_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set
WHERE NOT OLD.name_full <=> NEW.name_full
UNION
# Changed phone_number
SELECT NEW.id_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set
WHERE NOT OLD.phone_number <=> NEW.phone_number
UNION
# Changed postcode
SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set
WHERE NOT OLD.postcode <=> NEW.postcode

View File

@@ -0,0 +1,75 @@
# Shop Address
DROP TRIGGER IF EXISTS before_insert_Shop_User_Address;
DROP TRIGGER IF EXISTS before_update_Shop_User_Address;
DELIMITER //
CREATE TRIGGER before_insert_Shop_User_Address
BEFORE INSERT ON Shop_User_Address
FOR EACH ROW
BEGIN
SET NEW.created_on := IFNULL(NEW.created_on, NOW());
SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1));
END //
DELIMITER ;;
DELIMITER //
CREATE TRIGGER before_update_Shop_User_Address
BEFORE UPDATE ON Shop_User_Address
FOR EACH ROW
BEGIN
IF OLD.id_change_set <=> NEW.id_change_set THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'New change Set ID must be provided.';
END IF;
INSERT INTO Shop_User_Address_Audit (
id_user_address,
name_field,
value_prev,
value_new,
id_change_set
)
# Changed region
SELECT NEW.id_user_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set
WHERE NOT OLD.id_region <=> NEW.id_region
UNION
# Changed name_full
SELECT NEW.id_user_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set
WHERE NOT OLD.name_full <=> NEW.name_full
UNION
# Changed phone_number
SELECT NEW.id_user_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set
WHERE NOT OLD.phone_number <=> NEW.phone_number
UNION
# Changed postcode
SELECT NEW.id_user_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set
WHERE NOT OLD.postcode <=> NEW.postcode
UNION
# Changed address_line_1
SELECT NEW.id_user_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set
WHERE NOT OLD.address_line_1 <=> NEW.address_line_1
UNION
# Changed address_line_2
SELECT NEW.id_user_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set
WHERE NOT OLD.address_line_2 <=> NEW.address_line_2
UNION
# Changed city
SELECT NEW.id_user_address, 'city', OLD.city, NEW.city, NEW.id_change_set
WHERE NOT OLD.city <=> NEW.city
UNION
# Changed county
SELECT NEW.id_user_address, 'county', OLD.county, NEW.county, NEW.id_change_set
WHERE NOT OLD.county <=> NEW.county
UNION
# Changed active
SELECT NEW.id_user_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set
WHERE NOT (OLD.active <=> NEW.active)
;
END //
DELIMITER ;;

View File

@@ -78,6 +78,8 @@ BEGIN
COMMIT;
END IF;
DROP TABLE IF EXISTS tmp_Split_Split;
IF a_debug = 1 THEN
CALL p_debug_timing_reporting ( v_time_start );
END IF;

View File

@@ -0,0 +1,108 @@
DROP PROCEDURE IF EXISTS p_split_key_value_pair_csv;
DELIMITER //
CREATE PROCEDURE p_split_key_value_pair_csv (
IN a_guid BINARY(36)
, IN a_string LONGTEXT
, IN a_debug BIT
)
BEGIN
DECLARE v_has_string BIT;
DECLARE v_current_item VARCHAR(4000);
DECLARE v_time_start TIMESTAMP(6);
SET v_time_start := CURRENT_TIMESTAMP(6);
SET a_string := IFNULL(a_string, '');
SET a_debug := IFNULL(a_debug, 0);
SET v_has_string = CASE WHEN a_string = '' THEN 0 ELSE 1 END;
IF a_debug = 1 THEN
SELECT
a_guid
, a_string
, a_debug
;
END IF;
CALL p_validate_guid ( a_guid );
DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input;
DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split;
CREATE TEMPORARY TABLE tmp_Split_Input (
input_string TEXT
);
CREATE TEMPORARY TABLE tmp_Split_Split (
id INT AUTO_INCREMENT PRIMARY KEY
, key_column VARCHAR(4000)
, value_column VARCHAR(4000)
);
INSERT INTO tmp_Split_Input (
input_string
)
VALUES (
a_string
);
INSERT INTO tmp_Split_Split (key_column, value_column)
SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS key_column,
SUBSTRING_INDEX(t.pair, ':', -1) AS value_column
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(input_string, ',', n), ',', -1) pair
FROM temp_input
CROSS JOIN (
SELECT a.N + b.N * 10 + 1 n
FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
CROSS JOIN (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b
ORDER BY n
) numbers
WHERE n <= 1 + (LENGTH(input_string) - LENGTH(REPLACE(input_string, ',', '')))
) t;
IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN
START TRANSACTION;
INSERT INTO Split_Key_Value_Pair_Csv_Temp (
guid
, id
, key_column
, value_column
)
SELECT
a_guid
, id
, key_column
, value_column
FROM tmp_Split_Split
;
COMMIT;
END IF;
DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input;
DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split;
IF a_debug = 1 THEN
CALL p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;
/*
CALL p_split_key_value_pair_csv (
'nipsnipsnipsnipsnipsnipsnipsnipsnips'
, '1:100,2:200,3:300,4:400' # a_string
, 1
);
SELECT *
FROM Split_key_value_pair_csv_Temp
WHERE GUID = 'nipsnipsnipsnipsnipsnipsnipsnipsnips';
CALL p_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' );
*/

View File

@@ -0,0 +1,29 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_clear_split_key_value_pair_csv_temp;
DELIMITER //
CREATE PROCEDURE p_clear_split_key_value_pair_csv_temp (
IN a_guid BINARY(36)
)
BEGIN
CALL p_validate_guid( a_guid );
START TRANSACTION;
-- DROP TABLE IF EXISTS
DELETE FROM Split_Key_Value_Pair_Csv_Temp
WHERE GUID = a_guid
;
COMMIT;
END //
DELIMITER ;;
/*
CALL p_clear_split_key_value_pair_csv_temp ( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' );
*/

View File

@@ -0,0 +1,36 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_plant;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_plant (
IN a_get_inactive_plant BIT
)
BEGIN
SET a_get_inactive_plant = IFNULL(a_get_inactive_plant, 0);
SELECT
P.id_plant
, P.id_address
, A.id_region
, P.id_user_manager
, P.code
, P.name
, P.active
FROM Shop_Plant P
INNER JOIN Shop_Address A ON P.id_address = A.id_address
WHERE
a_get_inactive_plant = 1
OR P.active = 1
;
END //
DELIMITER ;;
/*
CALL p_shop_get_many_plant (
0 # a_get_inactive_plant
);
*/

View File

@@ -0,0 +1,37 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_storage_location;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_storage_location (
IN a_get_inactive_storage_location BIT
)
BEGIN
SET a_get_inactive_storage_location = IFNULL(a_get_inactive_storage_location, 0);
SELECT
SL.id_storage_location
, P.id_plant
, P.id_address
, A.id_region
, SL.code
, SL.name
, P.active
FROM Shop_Storage_Location SL
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
WHERE
a_get_inactive_storage_location = 1
OR SL.active = 1
;
END //
DELIMITER ;;
/*
CALL p_shop_get_many_storage_location (
0 # a_get_inactive_storage_location
);
*/

View File

@@ -37,7 +37,7 @@ BEGIN
4 -- id_product
, 1 -- id_category
, 'Laptops' -- name
, 1 -- has_variations
, 0 -- has_variations
, 2 -- id_access_level_required
, 2 -- display_order
, 1 -- active
@@ -69,10 +69,10 @@ BEGIN
END //
DELIMITER ;;
/*
CALL partsltd_prod.p_shop_save_product_test ();
DELETE FROM partsltd_prod.Shop_Product_Temp;
/*
DROP TABLE IF EXISTS tmp_Msg_Error;
*/

View File

@@ -464,6 +464,7 @@ END //
DELIMITER ;;
/*
CALL partsltd_prod.p_shop_get_many_product (
1 #'auth0|6582b95c895d09a70ba10fef', # a_id_user
@@ -483,7 +484,6 @@ CALL partsltd_prod.p_shop_get_many_product (
, 0 # a_debug
);
/*
select * FROM partsltd_prod.Shop_Calc_User_Temp;
select * FROM partsltd_prod.Shop_Product_Category;

View File

@@ -0,0 +1,221 @@
DROP FUNCTION IF EXISTS fn_shop_get_id_product_permutation_from_variation_csv_list;
DELIMITER //
CREATE FUNCTION fn_shop_get_id_product_permutation_from_variation_csv_list (
a_id_product INT
, a_variation_csv TEXT
)
RETURNS INT
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE v_id_permutation INT;
DECLARE done INT DEFAULT FALSE;
DECLARE v_id_variation_type INT;
DECLARE v_id_variation INT;
DECLARE v_id_permutation_tmp INT;
DECLARE cur CURSOR FOR
SELECT
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS UNSIGNED) AS id_variation_type,
CAST(SUBSTRING_INDEX(t.pair, ':', -1) AS UNSIGNED) AS id_variation
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(a_variation_csv, ',', n), ',', -1) pair
FROM (
SELECT a.N + b.N * 10 + 1 n
FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
CROSS JOIN (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b
ORDER BY n
) numbers
WHERE n <= 1 + (LENGTH(a_variation_csv) - LENGTH(REPLACE(a_variation_csv, ',', '')))
) t;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET v_id_permutation = NULL;
OPEN cur;
read_loop: LOOP
FETCH cur INTO v_id_variation_type, v_id_variation;
IF done THEN
LEAVE read_loop;
END IF;
IF v_id_permutation IS NULL THEN
-- First iteration: find initial v_id_permutations
SELECT PPVL.id_permutation INTO v_id_permutation
FROM partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL
INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PPVL.id_permutation = PP.id_permutation
INNER JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation
WHERE 1=1
AND PP.id_product = a_id_product
AND PPVL.id_variation = v_id_variation
AND PV.id_type = v_id_variation_type
;
ELSE
-- Subsequent iterations: narrow down the v_id_permutation
SELECT PPVL.id_permutation INTO v_id_permutation_tmp
FROM partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL
INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PPVL.id_permutation = PP.id_permutation
INNER JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation
WHERE 1=1
AND PP.id_product = a_id_product
AND PPVL.v_id_permutation = v_id_permutation
AND PPVL.id_variation = v_id_variation
AND PV.id_type = v_id_variation_type
;
IF v_id_permutation_tmp IS NULL THEN
-- If no match found, exit the loop
SET v_id_permutation := NULL;
LEAVE read_loop;
ELSE
SET v_id_permutation := v_id_permutation_tmp;
END IF;
END IF;
END LOOP;
CLOSE cur;
RETURN v_id_permutation;
END //
DELIMITER ;
/*
SELECT fn_shop_get_id_product_permutation_from_variation_csv_list ( 1, '1:1' ) AS id_permutation;
SELECT fn_shop_get_id_product_permutation_from_variation_csv_list ( 3, '' ) AS id_permutation;
*/
/*
-- Update the table using the function
UPDATE product_permutation_input
SET v_id_permutation = find_v_id_permutation(variation_csv)
WHERE v_id_permutation IS NULL;
*/
/*
select * from partsltd_prod.Shop_Variation
DROP PROCEDURE IF EXISTS p_shop_get_id_product_permutation_from_variation_csv_list;
DELIMITER //
CREATE PROCEDURE p_shop_get_id_product_permutation_from_variation_csv_list (
IN a_guid BINARY(36)
, IN a_debug BIT
)
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE v_id INT;
DECLARE v_row_id INT;
DECLARE v_variation_csv TEXT;
DECLARE v_id_permutation INT;
DECLARE v_time_start TIMESTAMP(6);
-- Cursor to iterate through unprocessed rows
DECLARE cur CURSOR FOR
SELECT id, session_guid, row_id, variation_csv
FROM product_permutation_input
WHERE v_id_permutation IS NULL;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET v_time_start := CURRENT_TIMESTAMP(6);
SET a_debug := IFNULL(a_debug, 0);
IF a_debug = 1 THEN
SELECT
a_guid
, a_debug
;
END IF;
CALL p_validate_guid ( a_guid );
OPEN cur;
read_loop: LOOP
FETCH cur INTO v_id, v_session_guid, v_row_id, v_variation_csv;
IF done THEN
LEAVE read_loop;
END IF;
-- Find matching v_id_permutation
SET v_id_permutation = NULL;
SELECT ppvl.v_id_permutation INTO v_id_permutation
FROM (
SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS id_variation_type,
SUBSTRING_INDEX(t.pair, ':', -1) AS id_variation
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(v_variation_csv, ',', numbers.n), ',', -1) pair
FROM (
SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 -- add more if needed
) numbers
WHERE CHAR_LENGTH(v_variation_csv) - CHAR_LENGTH(REPLACE(v_variation_csv, ',', '')) >= numbers.n - 1
) t
) parsed
INNER JOIN product_permutation_variation_link ppvl
ON parsed.id_variation_type = ppvl.id_variation_type
AND parsed.id_variation = ppvl.id_variation
GROUP BY ppvl.v_id_permutation
HAVING COUNT(*) = (LENGTH(v_variation_csv) - LENGTH(REPLACE(v_variation_csv, ',', '')) + 1)
LIMIT 1;
-- Update the v_id_permutation in the input table
UPDATE product_permutation_input
SET v_id_permutation = v_id_permutation
WHERE id = v_id;
END LOOP;
CLOSE cur;
IF EXISTS ( SELECT * FROM Shop_Get_Id_Product_Permutation_From_Variation_Csv_List_Temp WHERE GUID = a_guid LIMIT 1 ) THEN
IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN
START TRANSACTION;
INSERT INTO Split_Key_Value_Pair_Csv_Temp (
guid
, id
, key_column
, value_column
)
SELECT
a_guid
, id
, key_column
, value_column
FROM tmp_Split_Split
;
COMMIT;
END IF;
END IF;
DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input;
DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split;
IF a_debug = 1 THEN
CALL p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;
*/
/*
CALL p_shop_get_id_product_permutation_from_variation_csv_list (
'nipsnipsnipsnipsnipsnipsnipsnipsnips'
, '1:100,2:200,3:300,4:400' # a_string
, 1
);
SELECT *
FROM Split_key_value_pair_csv_Temp
WHERE GUID = 'nipsnipsnipsnipsnipsnipsnipsnipsnips';
CALL p_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' );
*/

View File

@@ -622,6 +622,7 @@ BEGIN
select * from tmp_Stock_Item;
select * from tmp_Permutation;
select * from tmp_Location_Storage;
select * from Shop_Storage_Location;
select * from tmp_Plant_Storage;
select * from tmp_Region_Storage;
*/
@@ -636,14 +637,19 @@ BEGIN
P.id_category,
t_SI.id_location_storage,
t_PS.id_plant,
t_RS.id_region,
PLANT.id_address AS id_address_plant,
t_RS.id_region AS id_region_plant,
SL.code AS code_storage_location,
SL.name AS name_storage_location,
PLANT.code AS code_plant,
PLANT.name AS name_plant,
SI.id_currency_cost,
CURRENCY.symbol AS symbol_currency_cost,
CURRENCY.code AS code_currency_cost,
SI.cost_local_VAT_excl,
SI.cost_local_VAT_incl,
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,
@@ -722,6 +728,7 @@ END //
DELIMITER ;;
/*
CALL p_shop_get_many_stock_item (
1, # a_id_user
1, # a_get_all_product_permutation
@@ -750,7 +757,6 @@ CALL p_shop_get_many_stock_item (
, 0 # a_debug
);
/*
DROP TABLE IF EXISTS tmp_Msg_Error;

View File

@@ -0,0 +1,646 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_save_stock_item;
DELIMITER //
CREATE PROCEDURE p_shop_save_stock_item (
IN a_comment VARCHAR(500)
, IN a_guid BINARY(36)
, IN a_id_user INT
, IN a_debug BIT
)
BEGIN
DECLARE v_code_type_error_bad_data VARCHAR(100);
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_id_access_level_edit INT;
DECLARE v_time_start TIMESTAMP(6);
DECLARE v_time_expire DATETIME;
DECLARE exit handler for SQLEXCEPTION
BEGIN
-- Get diagnostic information
GET DIAGNOSTICS CONDITION 1
@sqlstate = RETURNED_SQLSTATE
, @errno = MYSQL_ERRNO
, @text = MESSAGE_TEXT
;
-- Rollback the transaction
ROLLBACK;
-- Select the error information
-- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message;
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT
, id_type INT NULL
, code VARCHAR(50) NOT NULL
, msg VARCHAR(4000) NOT NULL
);
INSERT INTO tmp_Msg_Error (
id_type
, code
, msg
)
SELECT
NULL
, @errno
, @text
;
SELECT *
FROM tmp_Msg_Error;
DROP TABLE IF EXISTS tmp_Msg_Error;
END;
SET v_time_start := CURRENT_TIMESTAMP(6);
SET v_time_expire := DATE_ADD(v_time_start, INTERVAL 1000 YEAR);
SET v_code_type_error_bad_data := '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 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());
DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
CREATE TEMPORARY TABLE tmp_Stock_Item (
id_stock INT NOT NULL
, id_category INT NULL
, id_product INT NOT NULL
, id_permutation INT NULL
, id_pairs_variations VARCHAR(4000) NULL
, has_variations BIT NULL
, date_purchased DATETIME NOT NULL
, date_received DATETIME NULL
, id_location_storage INT NOT NULL
, id_currency_cost INT NOT NULL
, cost_local_VAT_incl FLOAT NOT NULL
, cost_local_VAT_excl FLOAT NOT NULL
, is_sealed BIT NOT NULL
, date_unsealed DATETIME NULL
, date_expiration DATETIME NOT NULL
, is_consumed BIT NOT NULL
, date_consumed DATETIME NULL
, active BIT NOT NULL
, can_view BIT NULL
, can_edit BIT NULL
, can_admin BIT NULL
, name_error VARCHAR(1000) NULL
, is_new BIT NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT
, id_type INT NULL
, code VARCHAR(50) NOT NULL
, msg VARCHAR(4000) NOT NULL
);
-- Get data from Temp table
INSERT INTO tmp_Stock_Item (
id_stock
-- , id_category
, id_product
, id_permutation
, id_pairs_variations
, has_variations
, date_purchased
, date_received
, id_location_storage
, id_currency_cost
, cost_local_VAT_incl
, cost_local_VAT_excl
, is_sealed
, date_unsealed
, date_expiration
, is_consumed
, date_consumed
, active
# , name_error
, is_new
)
SELECT
SI_T.id_stock
-- , IFNULL(SI_T.id_category, P.id_category) AS id_category
, IFNULL(IFNULL(SI_T.id_product, PP.id_product), 0) AS id_product
, IFNULL(IFNULL(SI_T.id_permutation, SI.id_permutation), 0) AS id_permutation
, TRIM(IFNULL(SI_T.id_pairs_variations, ''))
, CASE WHEN TRIM(IFNULL(SI_T.id_pairs_variations, '')) = '' THEN 0 ELSE 1 END AS has_variations
, IFNULL(IFNULL(SI_T.date_purchased, SI.date_purchased), v_time_start) AS date_purchased
, IFNULL(SI_T.date_received, SI.date_received) AS date_received
, IFNULL(IFNULL(SI_T.id_location_storage, SI.id_location_storage), 0) AS id_location_storage
, IFNULL(IFNULL(SI_T.id_currency_cost, SI.id_currency_cost), 0) AS id_currency_cost
, IFNULL(SI_T.cost_local_VAT_incl, SI.cost_local_VAT_incl) AS cost_local_VAT_incl
, IFNULL(SI_T.cost_local_VAT_excl, SI.cost_local_VAT_excl) AS cost_local_VAT_excl
, IFNULL(IFNULL(SI_T.is_sealed, SI.is_sealed), 1) AS is_sealed
, IFNULL(SI_T.date_unsealed, SI.date_unsealed) AS date_unsealed
, IFNULL(IFNULL(SI_T.date_expiration, SI.date_expiration), v_time_expire) AS date_expiration
, IFNULL(IFNULL(SI_T.is_consumed, SI.is_consumed), 0) AS is_consumed
, IFNULL(SI_T.date_consumed, SI.date_consumed) AS date_consumed
, IFNULL(IFNULL(SI_T.active, SI.active), 1) AS active
# , fn_shop_get_product_permutation_name(SI_T.id_permutation)
, CASE WHEN IFNULL(SI_T.id_stock, 0) < 1 THEN 1 ELSE 0 END AS is_new
FROM partsltd_prod.Shop_Stock_Item_Temp SI_T
LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON SI_T.id_stock = SI.id_stock
LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON SI_T.id_permutation = PP.id_permutation
-- LEFT JOIN Shop_Product P ON PP.id_product = P.id_product
WHERE SI_T.guid = a_guid
;
-- Missing Permutation IDs for setting new permutation for stock item
-- With variations
UPDATE tmp_Stock_Item t_SI
INNER JOIN partsltd_prod.Shop_Product P ON t_SI.id_product = P.id_product
SET t_SI.id_permutation = IFNULL(fn_shop_get_id_product_permutation_from_variation_csv_list ( t_SI.id_product, t_SI.id_pairs_variations ), 0)
WHERE 1=1
AND t_SI.id_permutation = 0
AND t_SI.has_variations = 1
;
-- Without variations
UPDATE tmp_Stock_Item t_SI
-- INNER JOIN Shop_Product P ON t_SI.id_product = P.id_product
INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_product = PP.id_product
SET t_SI.id_permutation = IFNULL(PP.id_permutation, 0)
WHERE 1=1
AND t_SI.id_permutation = 0
AND t_SI.has_variations = 0
;
-- Add stock item error names
UPDATE tmp_Stock_Item t_SI
INNER JOIN partsltd_prod.Shop_Product P ON t_SI.id_product = P.id_product
INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category
-- INNER JOIN Shop_Product_Permutation PP ON t_SI.id_product = PP.id_product
SET t_SI.name_error = CONCAT(
PC.name,
' - ',
P.name,
' - ',
CASE WHEN IFNULL(t_SI.id_permutation, 0) = 0 THEN '(No permutation)' ELSE fn_shop_get_product_permutation_name ( t_SI.id_permutation ) END
)
;
IF a_debug = 1 THEN
sElect * from tmp_Stock_Item;
END IF;
-- Validation
-- Missing mandatory fields
-- id_product
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE t_SI.id_product = 0 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
, CONCAT('The following stock item(s) do not have a product: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE t_SI.id_product = 0
;
END IF;
-- id_permutation
IF EXISTS (
SELECT *
FROM tmp_Stock_Item t_SI
LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation
WHERE 1=1
AND (
t_SI.id_permutation = 0
OR PP.active = 0
)
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
, CONCAT('A valid permutation could not be found for the variations selected for the following stock item(s): ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation
WHERE 1=1
AND (
t_SI.id_permutation = 0
OR PP.active = 0
)
;
END IF;
-- date_purchased
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE ISNULL(t_SI.date_purchased) 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
, CONCAT('The following stock item(s) do not have an purchase date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE ISNULL(t_SI.date_purchased)
;
END IF;
-- id_location_storage
IF EXISTS (
SELECT *
FROM tmp_Stock_Item t_SI
INNER JOIN partsltd_prod.Shop_Storage_Location SL
ON t_SI.id_location_storage = SL.id_location
AND SL.active = 1
WHERE ISNULL(SL.id_location)
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
, CONCAT('The following stock item(s) do not have a valid storage location: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
INNER JOIN partsltd_prod.Shop_Storage_Location SL
ON t_SI.id_location_storage = SL.id_location
AND SL.active = 1
WHERE ISNULL(SL.id_location)
;
END IF;
-- id_currency_cost
IF EXISTS (
SELECT *
FROM tmp_Stock_Item t_SI
INNER JOIN partsltd_prod.Shop_Currency C
ON t_SI.id_currency_cost = C.id_currency
AND C.active = 1
WHERE ISNULL(C.id_currency)
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
, CONCAT('The following stock item(s) do not have a valid cost currency: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
INNER JOIN partsltd_prod.Shop_Currency C
ON t_SI.id_currency_cost = C.id_currency
AND C.active = 1
WHERE ISNULL(C.id_currency)
;
END IF;
-- cost_local_VAT_excl
IF EXISTS (
SELECT *
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND (
ISNULL(t_SI.cost_local_VAT_excl)
OR t_SI.cost_local_VAT_excl < 0
)
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
, CONCAT('The following stock item(s) do not have a valid cost excluding VAT: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND (
ISNULL(t_SI.cost_local_VAT_excl)
OR t_SI.cost_local_VAT_excl < 0
)
;
END IF;
-- cost_local_VAT_incl
IF EXISTS (
SELECT *
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND (
ISNULL(t_SI.cost_local_VAT_incl)
OR t_SI.cost_local_VAT_incl < 0
)
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
, CONCAT('The following stock item(s) do not have a valid cost including VAT: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND (
ISNULL(t_SI.cost_local_VAT_incl)
OR t_SI.cost_local_VAT_incl < t_SI.cost_local_VAT_excl
)
;
END IF;
-- date_received
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_received) AND t_SI.date_received < t_SI.date_purchased 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
, CONCAT('The following stock item(s) do not have a valid received date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND NOT ISNULL(t_SI.date_received)
AND t_SI.date_received < t_SI.date_purchased
;
END IF;
-- date_unsealed
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_unsealed) AND t_SI.date_unsealed < t_SI.date_purchased 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
, CONCAT('The following stock item(s) do not have a valid unsealed date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND NOT ISNULL(t_SI.date_received)
AND t_SI.date_received < t_SI.date_purchased
;
END IF;
-- date_expiration
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_expiration) AND t_SI.date_expiration < t_SI.date_purchased 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
, CONCAT('The following stock item(s) do not have a valid expiration date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND NOT ISNULL(t_SI.date_expiration)
AND t_SI.date_expiration < t_SI.date_purchased
;
END IF;
-- date_consumed
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_consumed) AND t_SI.date_consumed < t_SI.date_purchased 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
, CONCAT('The following stock item(s) do not have a valid consumed date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE 1=1
AND NOT ISNULL(t_SI.date_consumed)
AND t_SI.date_consumed < t_SI.date_purchased
;
END IF;
-- Permissions
SET v_ids_product_permission := ( SELECT GROUP_CONCAT(t_SI.id_product SEPARATOR ',') FROM tmp_Stock_Item t_SI );
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
, FALSE -- a_get_inactive_users
, v_id_permission_product
, v_id_access_level_edit
, v_ids_product_permission
, 0 -- a_debug
);
UPDATE tmp_Stock_Item t_SI
INNER JOIN Shop_Product P ON t_SI.id_product = P.id_product
INNER JOIN Shop_Calc_User_Temp UE_T
ON P.id_product = UE_T.id_product
AND UE_T.GUID = a_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
;
CALL p_shop_clear_calc_user(
a_guid
, 0 -- a_debug
);
IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE IFNULL(t_SI.can_edit, 0) = 0 LIMIT 1) THEN
INSERT INTO tmp_Msg_Error (
guid
, id_type
, code
, msg
)
SELECT
a_guid AS GUID
, v_id_type_error_bad_data
, v_code_type_error_bad_data
, CONCAT('The following stock item(s) do not have product edit permission: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg
FROM tmp_Stock_Item t_SI
WHERE IFNULL(t_SI.can_edit, 0) = 0
;
END IF;
END IF;
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();
-- select * from partsltd_prod.Shop_Stock_Item
UPDATE partsltd_prod.Shop_Stock_Item SI
INNER JOIN tmp_Stock_Item t_SI
ON SI.id_stock = t_SI.id_stock
SET
SI.id_permutation = t_SI.id_permutation
, SI.date_purchased = t_SI.date_purchased
, SI.date_received = t_SI.date_received
, SI.id_location_storage = t_SI.id_location_storage
, SI.id_currency_cost = t_SI.id_currency_cost
, SI.cost_local_VAT_excl = t_SI.cost_local_VAT_excl
, SI.cost_local_VAT_incl = t_SI.cost_local_VAT_incl
, SI.is_sealed = t_SI.is_sealed
, SI.date_unsealed = t_SI.date_unsealed
, SI.date_expiration = t_SI.date_expiration
, SI.is_consumed = t_SI.is_consumed
, SI.date_consumed = t_SI.date_consumed
, SI.active = t_SI.active
, SI.id_change_set = v_id_change_set
;
END IF;
INSERT INTO partsltd_prod.Shop_Stock_Item (
id_permutation
, date_purchased
, date_received
, id_location_storage
, id_currency_cost
, cost_local_VAT_excl
, cost_local_VAT_incl
, is_sealed
, date_unsealed
, date_expiration
, is_consumed
, date_consumed
, active
, created_by
, created_on
)
SELECT
t_SI.id_permutation
, t_SI.date_purchased
, t_SI.date_received
, t_SI.id_location_storage
, t_SI.id_currency_cost
, t_SI.cost_local_VAT_excl
, t_SI.cost_local_VAT_incl
, t_SI.is_sealed
, t_SI.date_unsealed
, t_SI.date_expiration
, t_SI.is_consumed
, t_SI.date_consumed
, t_SI.active
, a_id_user AS created_by
, v_time_start AS created_on
FROM tmp_Stock_Item t_SI
WHERE
is_new = 1
AND active = 1
;
DELETE FROM partsltd_prod.Shop_Stock_Item_Temp
WHERE GUID = a_guid;
COMMIT;
END IF;
SELECT * FROM tmp_Msg_Error;
DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
END //
DELIMITER ;;
/*
DELETE FROM Shop_Product_Permutation_Temp
WHERE id_permutation = 1
;
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,
guid
)
VALUES
(
1 -- id_permutation,
, 1 -- id_product,
, 'Good Reddy Teddy' -- description,
, 5.0 -- cost_local,
, 1 -- id_currency_cost,
, 3.0 -- profit_local_min,
, 14 -- latency_manufacture_days,
, 1 -- id_unit_measurement_quantity,
, 1.0 -- count_unit_measurement_quantity,
, 3.0 -- quantity_min,
, 99.0 -- quantity_max,
, 1.0 -- quantity_stock,
, False -- is_subscription,
, null -- id_unit_measurement_interval_recurrence,
, null -- count_interval_recurrence,
, null -- id_stripe_product,
, False -- does_expire_faster_once_unsealed,
, null -- id_unit_measurement_interval_expiration_unsealed,
, null -- count_interval_expiration_unsealed,
, True -- active,
, 'NIPS' -- guid
)
;
select 'Shop_Product_Permutation_Temp before call';
SELECT * FROM Shop_Product_Permutation_Temp;
SELECT 'Shop_Product_Permutation before call' AS result_name;
select * FROM Shop_Product_Permutation;
CALL p_shop_save_product_permutation (
1, -- 'auth0|6582b95c895d09a70ba10fef', # a_id_user
'Initial data', # a_comment
'NIPS' # a_guid
);
SELECT 'Shop_Product_Permutation_Temp after call' AS result_name;
select * FROM Shop_Product_Permutation_Temp;
SELECT 'Shop_Product_Permutation after call' AS result_name;
select * FROM Shop_Product_Permutation;
DELETE FROM Shop_Product_Permutation_Temp
WHERE id_permutation = 1;
*/

View File

@@ -0,0 +1,101 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_stock_item_test;
DELIMITER //
CREATE PROCEDURE p_shop_save_stock_item_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_Stock_Item
;
SELECT *
FROM partsltd_prod.Shop_Stock_Item_Temp
;
START TRANSACTION;
INSERT INTO partsltd_prod.Shop_Stock_Item_Temp (
id_stock
-- id_category
, id_product
, id_permutation
, id_pairs_variations
-- , has_variations
, date_purchased
, date_received
, id_location_storage
, id_currency_cost
, cost_local_VAT_excl
, cost_local_VAT_incl
, is_sealed
, date_unsealed
, date_expiration
, is_consumed
, date_consumed
, active
, guid
)
VALUES (
-1 -- id_stock
-- 1 -- id_category
, 4 -- id_product
, NULL -- id_permutation
, NULL -- id_pairs_variations
-- , FALSE -- 0 -- has_variations
, '2025-09-05 00:00' -- date_purchased
, NULL -- date_received
, 1 -- id_location_storage
, 1 -- id_currency_cost
, 10 -- cost_local_VAT_excl
, 12 -- cost_local_VAT_incl
, 1 -- is_sealed
, NULL -- date_unsealed
, NULL -- date_expiration
, FALSE -- 0 -- is_consumed
, NULL -- date_consumed
, 1 -- active
, v_guid
);
COMMIT;
SELECT *
FROM partsltd_prod.Shop_Stock_Item_Temp
WHERE GUID = v_guid
;
CALL partsltd_prod.p_shop_save_Stock_Item (
'Test save Stock_Item' -- comment
, v_guid -- guid
, 1 -- id_user
, 0 -- debug
);
SELECT *
FROM partsltd_prod.Shop_Stock_Item
;
SELECT *
FROM partsltd_prod.Shop_Stock_Item_Temp
;
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END //
DELIMITER ;;
CALL partsltd_prod.p_shop_save_stock_item_test ();
DELETE FROM partsltd_prod.Shop_Stock_Item_Temp;
/*
update shop_product p set p.has_variations = 0 where id_product = 4
DROP TABLE IF EXISTS tmp_Msg_Error;
*/

View File

@@ -1,7 +1,5 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_get_many_user;
@@ -15,48 +13,81 @@ CREATE PROCEDURE p_get_many_user (
, IN a_get_first_user_only BIT
, IN a_ids_user LONGTEXT
, IN a_ids_user_auth0 LONGTEXT
, IN a_debug BIT
)
BEGIN
DECLARE v_id_access_level_admin INT;
DECLARE v_id_access_level_view INT;
DECLARE v_id_permission_store_admin INT;
DECLARE v_id_permission_user INT;
DECLARE v_id_permission_user_admin INT;
DECLARE v_ids_permission_required VARCHAR(4000);
DECLARE v_now TIMESTAMP;
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;
DECLARE v_has_filter_user BIT;
DECLARE v_has_filter_user_auth0 BIT;
DECLARE v_guid BINARY(36);
DECLARE v_rank_max INT;
DECLARE v_time_start TIMESTAMP(6);
SET v_time_start := CURRENT_TIMESTAMP(6);
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1);
SET v_id_permission_store_admin := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_ADMIN' LIMIT 1);
SET v_id_permission_user := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_USER' LIMIT 1);
SET v_id_permission_user_admin := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_USER_ADMIN' 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_id_access_level_admin := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1);
SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1);
SET v_id_permission_store_admin := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_ADMIN' LIMIT 1);
SET v_id_permission_user := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_USER' LIMIT 1);
SET v_id_permission_user_admin := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_USER_ADMIN' LIMIT 1);
SET v_code_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1);
SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_error_bad_data LIMIT 1);
SET v_ids_permission_required := CONCAT(v_id_permission_user, ',', v_id_permission_user_admin, ',', v_id_permission_store_admin);
SET a_get_all_user := IFNULL(a_get_all_user, 1);
SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0);
SET a_get_first_user_only := IFNULL(a_get_first_user_only, 0);
SET a_ids_user := TRIM(IFNULL(a_ids_user, ''));
SET a_ids_user_auth0 := TRIM(IFNULL(a_ids_user_auth0, ''));
SET a_debug := IFNULL(a_debug, 0);
IF a_debug = 1 THEN
SELECT
a_id_user
, a_id_user_auth0
, a_get_all_user
, a_get_inactive_user
, a_get_first_user_only
, a_ids_user
, a_ids_user_auth0
, a_debug
;
END IF;
DROP TEMPORARY TABLE IF EXISTS tmp_User;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
CREATE TEMPORARY TABLE tmp_User (
id_user INT NOT NULL,
rank_user INT NULL
id_user INT NULL
, rank_user INT NULL
, can_admin_store BIT NULL
, can_admin_user BIT NULL
);
CREATE TEMPORARY TABLE 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,
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
);
IF ISNULL(a_id_user) AND NOT ISNULL(a_id_user_auth0) THEN
SET a_id_user := (SELECT U.id_user FROM Shop_User U WHERE U.id_user_auth0 LIKE CONCAT('%', a_id_user_auth0, '%') LIMIT 1);
SET a_id_user := (SELECT U.id_user FROM partsltd_prod.Shop_User U WHERE U.id_user_auth0 = a_id_user_auth0 LIMIT 1); -- LIKE CONCAT('%', a_id_user_auth0, '%') LIMIT 1);
END IF;
IF ISNULL(a_id_user) THEN
@@ -68,150 +99,352 @@ 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('User ID required for authorisation.')
)
;
END IF;
SET v_has_filter_user := CASE WHEN a_ids_user = '' AND a_ids_user_auth0= '' THEN 0 ELSE 1 END;
SET v_has_filter_user := CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END;
SET v_has_filter_user_auth0 := CASE WHEN a_ids_user_auth0 = '' THEN 0 ELSE 1 END;
IF v_has_filter_user THEN
INSERT INTO tmp_User (
id_user
-- , active
, rank_user
)
SELECT
DISTINCT U.id_user
-- S.active
, RANK() OVER (ORDER BY id_user ASC) AS rank_user
FROM Shop_User U
WHERE 1=1
AND (
FIND_IN_SET(U.id_user, a_ids_user) > 0
OR FIND_IN_SET(U.id_user_auth0, a_ids_user_auth0) > 0
)
AND (
a_get_inactive_user
OR U.active
)
/*Shop_Calc_User_Temp UE_T
WHERE 1=1
AND UE_T.guid = v_guid
AND UE_T.active = 1
*/
IF a_debug = 1 THEN
SELECT
v_has_filter_user
, v_has_filter_user_auth0
;
IF a_get_first_user_only THEN
DELETE t_U
FROM tmp_User t_U
WHERE t_U.rank_user > 1
;
END IF;
END IF;
-- 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_Calc_User_Temp;
-- User IDs
IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user = 1) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_user, ',', FALSE);
CALL p_shop_calc_user(
v_guid, -- guid
a_id_user, -- ids_user
FALSE, -- get_inactive_user
CONCAT(v_id_permission_user, ',', v_id_permission_user_admin, ',', v_id_permission_store_admin), -- ids_permission
v_id_access_level_view, -- ids_access_level
'' -- ids_product
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user = 1) THEN
IF EXISTS (
SELECT *
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)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_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)
;
ELSE
INSERT INTO tmp_User (
id_user
, rank_user
)
SELECT
U.id_user
, RANK() OVER (ORDER BY U.id_user DESC) AS rank_user
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user
WHERE
(
a_get_all_user = 1
OR (
v_has_filter_user = 1
AND NOT ISNULL(t_S.as_int)
)
)
AND (
a_get_inactive_user = 1
OR U.active = 1
)
;
END IF;
END IF;
-- Auth0 User IDs
IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user_auth0 = 1) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_user_auth0, ',', FALSE);
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
)
SELECT
substring
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user_auth0 = 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0
WHERE
ISNULL(t_S.substring)
OR ISNULL(U.id_user_auth0)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_error_bad_data,
CONCAT('Invalid or inactive Auth0 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.substring = U.id_user_auth0
WHERE
ISNULL(t_S.substring)
OR ISNULL(U.id_user_auth0)
;
ELSE
SET v_rank_max := IFNULL((SELECT rank_user FROM tmp_User ORDER BY rank_user DESC LIMIT 1), 0);
INSERT INTO tmp_User (
id_user
, rank_user
)
SELECT
U.id_user
, v_rank_max + (RANK() OVER (ORDER BY U.id_user DESC)) AS rank_user
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0
WHERE
(
a_get_all_user = 1
OR (
v_has_filter_user_auth0 = 1
AND NOT ISNULL(t_S.substring)
)
)
AND (
a_get_inactive_user = 1
OR U.active = 1
)
;
END IF;
END IF;
IF a_debug = 1 THEN
SELECT * FROM tmp_User;
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF a_get_first_user_only THEN
DELETE t_U
FROM tmp_User t_U
WHERE t_U.rank_user > 1
;
END IF;
END IF;
IF a_debug = 1 THEN
SELECT * FROM tmp_User;
END IF;
-- Can admin store
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF a_debug = 1 THEN
SELECT
v_guid -- guid
, a_id_user -- ids_user
, FALSE -- get_inactive_user
, v_id_permission_store_admin -- ids_permission
, v_id_access_level_admin -- ids_access_level
, '' -- ids_product
, 0 -- a_debug
;
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp;
END IF;
CALL partsltd_prod.p_shop_calc_user(
v_guid -- guid
, a_id_user -- ids_user
, FALSE -- get_inactive_user
, v_id_permission_store_admin -- ids_permission
, v_id_access_level_admin -- ids_access_level
, '' -- ids_product
, 0 -- a_debug
);
-- select * from Shop_Calc_User_Temp;
IF a_debug = 1 THEN
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid;
END IF;
UPDATE tmp_User t_U
INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT
ON CUT.GUID = v_guid
AND t_U.id_user = CUT.id_user
SET t_U.can_admin_store = CUT.can_admin
;
CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE );
END IF;
-- Can admin user
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF a_debug = 1 THEN
SELECT
v_guid -- guid
, a_id_user -- ids_user
, FALSE -- get_inactive_user
, v_id_permission_user_admin -- ids_permission
, v_id_access_level_admin -- ids_access_level
, '' -- ids_product
, 0 -- a_debug
;
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp;
END IF;
CALL partsltd_prod.p_shop_calc_user(
v_guid -- guid
, a_id_user -- ids_user
, FALSE -- get_inactive_user
, v_id_permission_user_admin -- ids_permission
, v_id_access_level_admin -- ids_access_level
, '' -- ids_product
, 0 -- a_debug
);
IF a_debug = 1 THEN
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid;
END IF;
UPDATE tmp_User t_U
INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT
ON CUT.GUID = v_guid
AND t_U.id_user = CUT.id_user
SET t_U.can_admin_user = CUT.can_admin
;
CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE );
END IF;
-- Permissions
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF a_debug = 1 THEN
SELECT
v_guid -- guid
, a_id_user -- ids_user
, FALSE -- get_inactive_user
, v_ids_permission_required -- ids_permission
, v_id_access_level_view -- ids_access_level
, '' -- ids_product
, 0 -- a_debug
;
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp;
END IF;
CALL partsltd_prod.p_shop_calc_user(
v_guid -- guid
, a_id_user -- ids_user
, FALSE -- get_inactive_user
, v_ids_permission_required -- ids_permission
, v_id_access_level_view -- ids_access_level
, '' -- ids_product
, 0 -- a_debug
);
IF a_debug = 1 THEN
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid;
END IF;
IF NOT EXISTS (
SELECT can_view
FROM Shop_Calc_User_Temp UE_T
FROM partsltd_prod.Shop_Calc_User_Temp CUT
WHERE 1=1
AND UE_T.GUID = v_guid
AND UE_T.id_permission_required = v_id_permission_user
AND CUT.GUID = v_guid
AND can_view = 1
-- AND FIND_IN_SET(v_ids_permission_required, CUT.id_permission_required) > 0
) THEN
INSERT INTO tmp_Msg_Error (
guid,
id_type,
code,
msg
)
VALUES (
v_guid,
v_id_type_error_data,
v_code_error_data,
CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_user LIMIT 1))
v_id_type_error_bad_data,
v_code_error_bad_data,
-- CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_id_permission_user LIMIT 1))
-- CONCAT('You do not have view permissions for ', (SELECT GROUP_CONCAT(name SEPARATOR ', ') FROM partsltd_prod.Shop_Permission WHERE FIND_IN_SET(v_id_permission_user, id_permission) > 0))
CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission P INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT ON P.id_permission = CUT.id_permission_required WHERE GUID = v_guid AND IFNULL(can_view, 0) = 0 LIMIT 1)) -- WHERE IFNULL(CUT.can_view, 0) = 0
)
;
ELSE
-- INSERT INTO
SET a_debug := a_debug;
END IF;
CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE );
END IF;
-- Returns
/* NULL record required for flask sql_alchemy to detect result set
IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = v_guid) THEN
/* NULL record required for flask sql_alchemy to detect result set */
IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN
DELETE FROM tmp_User;
INSERT INTO tmp_User ( id_user )
VALUES ( NULL );
END IF;
*/
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = v_guid) THEN
SELECT
U.id_user
, U.id_user_auth0
, U.firstname
, U.surname
, U.email
, U.is_email_verified
, U.id_currency_default
, U.id_region_default
, U.is_included_VAT_default
, U.is_super_user
, UE_T_STORE.can_admin_store AS can_admin_store
, UE_T_USER.can_admin_user AS can_admin_user
FROM tmp_User t_U
INNER JOIN Shop_User U ON t_U.id_user = U.id_user
INNER JOIN (
SELECT
id_user
, id_permission_required
, can_admin AS can_admin_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
) UE_T_STORE ON t_U.id_user = UE_T_STORE.id_user
INNER JOIN (
SELECT
id_user
, id_permission_required
, can_admin AS can_admin_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
) UE_T_USER ON t_U.id_user = UE_T_USER.id_user
;
ELSE
SELECT
NULL AS id_user
, NULL AS id_user_auth0
, NULL AS firstname
, NULL AS surname
, NULL AS email
, NULL AS is_email_verified
, NULL AS id_currency_default
, NULL AS id_region_default
, NULL AS is_included_VAT_default
, NULL AS is_super_user
, NULL AS can_admin_store
, NULL AS can_admin_user
;
END IF;
SELECT
U.id_user
, U.id_user_auth0
, U.firstname
, U.surname
, U.email
, U.is_email_verified
, U.id_currency_default
, U.id_region_default
, U.is_included_VAT_default
, U.is_super_user
, t_U.can_admin_store
, t_U.can_admin_user
FROM tmp_User t_U
INNER JOIN partsltd_prod.Shop_User U ON t_U.id_user = U.id_user
;
# Errors
SELECT
@@ -221,27 +454,33 @@ BEGIN
MET.name,
MET.description
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
;
IF a_debug = 1 THEN
SELECT * FROM tmp_User;
END IF;
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_User;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
/*
DELETE FROM Shop_Calc_User_Temp
DELETE FROM partsltd_prod.Shop_Calc_User_Temp
WHERE GUID = v_guid;
*/
CALL p_shop_clear_calc_user(v_guid);
IF a_debug = 1 THEN
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;
/*
CALL p_get_many_user (
NULL # a_id_user
, 'auth0|6582b95c895d09a70ba10fef' # a_id_user_auth0
@@ -249,13 +488,15 @@ CALL p_get_many_user (
, 0 # a_get_inactive_user
, 0 # a_get_first_user_only
, NULL # a_ids_user
, 'auth0|6582b95c895d09a70ba10fef' # a_ids_user_auth0 # ' --
, 'auth0|6582b95c895d09a70ba10fef' # a_ids_user_auth0
, 1 -- a_debug
);
select * from Shop_Calc_User_Temp;
delete from Shop_Calc_User_Temp;
select * FROM partsltd_prod.Shop_Calc_User_Temp;
delete FROM partsltd_prod.Shop_Calc_User_Temp;
SELECT *
FROM SHOP_USER;
FROM partsltd_prod.Shop_USER;
CALL p_get_many_user(
NULL -- :a_id_user,

View File

@@ -86,6 +86,14 @@ VALUES
;
*/
# Addresses
INSERT INTO Shop_Address (
id_region, postcode, address_line_1, address_line_2, city, county
)
VALUES (
1, 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire'
);
# Plants
INSERT INTO Shop_Plant (
code, name, id_address, id_user_manager
@@ -552,7 +560,10 @@ VALUES
(4, 'SALES_AND_PURCHASING', 'Sales and Purchasing'),
(5, 'MANUFACTURING', 'Manufacturing')
;
/*
select * from Shop_Permission
select * from Shop_Role_Permission_Link
*/
# Permissions
INSERT INTO Shop_Permission (
display_order, code, name, id_permission_group, id_access_level_required
@@ -627,8 +638,8 @@ VALUES
(1, 1)
;
# Addresses
INSERT INTO Shop_Address (
# User Addresses
INSERT INTO Shop_User_Address (
id_user, id_region, name_full, phone_number, postcode, address_line_1, address_line_2, city, county
)
SELECT U.id_user, 1, CONCAT(U.firstname, ' ', U.surname), '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire'
@@ -697,7 +708,7 @@ INSERT INTO Shop_Supplier (
, id_currency
)
VALUES
('Malt Kiln Farm Shop', NULL, NULL, 2, '01788 832640', NULL, 'farmshop@maltkilnfarmshop.co.uk', 'https://www.maltkilnfarmshop.co.uk/', 1)
('Malt Kiln Farm Shop', NULL, NULL, 1, '01788 832640', NULL, 'farmshop@maltkilnfarmshop.co.uk', 'https://www.maltkilnfarmshop.co.uk/', 1)
;
/*

View File

@@ -1,6 +1,6 @@
/*
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
@@ -24,4 +24,7 @@ FROM
WHERE
TABLE_SCHEMA = 'PARTS'
-- AND TABLE_NAME = 'your_table_name'
;
;
*/

View File

@@ -2,6 +2,7 @@
1000_tbl_Shop_Product_Change_Set.sql
1000_tbl_Split_Temp.sql
1001_tbl_Shop_User_Change_Set.sql
1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql
1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql
1003_tbl_Shop_Access_Level.sql
1004_tbl_Shop_Access_Level_Audit.sql
@@ -18,7 +19,9 @@
1103_tbl_Shop_Region_Branch.sql
1104_tbl_Shop_Region_Branch_Audit.sql
1105_tbl_Shop_Region_Branch_Temp.sql
1106_tbl_Shop_Address.sql
1106_tbl_Shop_Plant.sql
1107_tbl_Shop_Address_Audit.sql
1107_tbl_Shop_Plant_Audit.sql
1108_tbl_Shop_Plant_Temp.sql
1109_tbl_Shop_Storage_Location.sql
@@ -67,9 +70,7 @@
1233_tbl_Shop_Discount.sql
1234_tbl_Shop_Discount_Audit.sql
1236_tbl_Shop_Discount_Region_Currency_Link.sql
1236_tbl_Shop_Product_Currency_Region_Link.sql
1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql
1237_tbl_Shop_Product_Currency_Region_Link_Audit.sql
1300_tbl_Shop_Permission_Group.sql
1301_tbl_Shop_Permission_Group_Audit.sql
1303_tbl_Shop_Permission.sql
@@ -82,8 +83,8 @@
1313_tbl_Shop_User_Audit.sql
1315_tbl_Shop_User_Role_Link.sql
1316_tbl_Shop_User_Role_Link_Audit.sql
1318_tbl_Shop_Address.sql
1319_tbl_Shop_Address_Audit.sql
1318_tbl_Shop_User_Address.sql
1319_tbl_Shop_User_Address_Audit.sql
1321_tbl_Shop_User_Basket.sql
1322_tbl_Shop_User_Basket_Audit.sql
1397_tbl_Shop_Order_Status.sql
@@ -118,6 +119,7 @@
3014_tri_Shop_Image_Type.sql
3100_tri_Shop_Region.sql
3103_tri_Shop_Region_Branch.sql
3106_tri_Shop_Address.sql
3109_tri_Shop_Storage_Location.sql
3115_tri_Shop_Currency.sql
3118_tri_Shop_Tax_Or_Surcharge.sql
@@ -140,7 +142,7 @@
3309_tri_Shop_Role_Permission_Link.sql
3312_tri_Shop_User.sql
3315_tri_Shop_User_Role_Link.sql
3318_tri_Shop_Address.sql
3318_tri_Shop_User_Address.sql
3321_tri_Shop_User_Basket.sql
3324_tri_Shop_User_Order_Status.sql
3400_tri_Shop_Supplier.sql
@@ -157,24 +159,31 @@
6000_p_split.sql
6001_p_clear_split_temp.sql
6001_p_validate_guid.sql
6003_p_split_key_value_pair_csv.sql
6004_p_clear_split_key_value_pair_csv_temp.sql
6206_fn_shop_get_product_permutation_name.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
7106_p_shop_get_many_plant.sql
7109_p_shop_get_many_storage_location.sql
7116_p_shop_get_many_currency.sql
7122_p_shop_get_many_unit_measurement.sql
7200_p_shop_save_product_category.sql
7200_p_shop_save_product_category_test.sql
7202_p_shop_clear_calc_product_permutation.sql
7203_p_shop_save_product.sql
7203_p_shop_save_product_test.sql
7204_p_shop_calc_product_permutation.sql
7204_p_shop_get_many_product.sql
7205_p_shop_get_many_stripe_product_new.sql
7206_p_shop_save_permutation.sql
7206_p_shop_save_product_permutation.sql
7210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql
7210_p_shop_get_many_product_variation.sql
7219_p_shop_get_many_stock_item.sql
7220_p_shop_save_stock_item.sql
7220_p_shop_save_stock_item_test.sql
7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql
7223_p_shop_get_many_stripe_price_new.sql
7312_p_shop_save_user.sql
@@ -193,4 +202,3 @@
9000_populate.sql
9001_view.sql
9010_anal.sql
DEPRECATED

View File

@@ -33,3 +33,15 @@ tr {
visibility: hidden;
}
*/
table textarea {
width: 95% !important;
}
table select {
width: 100% !important;
}
table input {
width: 90% !important;
}

View File

@@ -107,17 +107,6 @@
min-width: 6vh;
}
textarea {
width: 95% !important;
}
select {
width: 100% !important;
}
input {
width: 90% !important;
}
td > input, td > select, td > textarea, .container-input > input, .container-input > select, .container-input > textarea {
border: 2px solid var(--c_purple);

View File

@@ -4,36 +4,82 @@ th, td {
}
.category {
width: 12%;
#tableMain {
max-width: 90vw;
}
.product {
width: 12%;
#tableMain thead tr th.category, #tableMain tbody tr td.category {
width: 8vh;
min-width: 8vh;
}
.variations {
width: 12%;
}
.currency {
width: 12%;
}
.cost-local-VAT-incl {
width: 10%;
}
.date-puchased, .date-received, .date-unsealed, .date-expiration, .date-consumed {
width: 6%;
}
.storage-location {
width: 12%;
}
.active {
width: 5%;
#tableMain thead tr th.product, #tableMain tbody tr td.product,
#tableMain thead tr th.storage_location, #tableMain tbody tr td.storage_location {
width: 10vh;
min-width: 10vh;
}
.row-new {
visibility: hidden;
#tableMain thead tr th.product_variations.collapsed, #tableMain tbody tr td.product_variations.collapsed {
width: 10vh;
min-width: 10vh;
display: table-cell !important;
}
#tableMain thead tr th.product_variations, #tableMain tbody tr td.product_variations {
width: 20vh;
min-width: 20vh;
}
#tableMain tbody tr td.product_variations table thead tr th, #tableMain tbody tr td.product_variations table tbody tr td {
width: 8vh;
min-width: 8vh;
}
#tableMain tbody tr td.product_variations table thead tr th:last-of-type, #tableMain tbody tr td.product_variations table tbody tr td:last-of-type {
width: 4vh;
min-width: 4vh;
}
textarea, select, input {
width: 100% !important;
#tableMain thead tr th.id_currency_cost.collapsed, #tableMain tbody tr td.id_currency_cost.collapsed {
width: 9vh;
min-width: 9vh;
}
#tableMain thead tr th.id_currency_cost, #tableMain tbody tr td.id_currency_cost {
width: 11vh;
min-width: 11vh;
}
#tableMain thead tr th.cost_local_vat_excl, #tableMain tbody tr td.cost_local_vat_excl,
#tableMain thead tr th.cost_local_vat_incl, #tableMain tbody tr td.cost_local_vat_incl {
width: 9vh;
min-width: 9vh;
}
#tableMain thead tr th.storage-location.collapsed, #tableMain tbody tr td.storage-location.collapsed {
width: 10vh;
min-width: 10vh;
display: table-cell !important;
}
#tableMain thead tr th.storage-location, #tableMain tbody tr td.storage-location {
width: 20vh;
min-width: 20vh;
}
#tableMain tbody tr td.storage-location table thead tr th, #tableMain tbody tr td.storage-location table tbody tr td {
width: 8vh;
min-width: 8vh;
}
#tableMain tbody tr td.storage-location table thead tr th:last-of-type, #tableMain tbody tr td.storage-location table tbody tr td:last-of-type {
width: 4vh;
min-width: 4vh;
}
#tableMain thead tr th.active, #tableMain tbody tr td.active,
#tableMain thead tr th.is_sealed, #tableMain tbody tr td.is_sealed,
#tableMain thead tr th.is_consumed, #tableMain tbody tr td.is_consumed {
width: 6vh;
min-width: 6vh;
}
#tableMain thead tr th.date_purchased, #tableMain tbody tr td.date_purchased,
#tableMain thead tr th.date_received, #tableMain tbody tr td.date_received,
#tableMain thead tr th.date_unsealed, #tableMain tbody tr td.date_unsealed,
#tableMain thead tr th.date_expiration, #tableMain tbody tr td.date_expiration,
#tableMain thead tr th.date_consumed, #tableMain tbody tr td.date_consumed {
width: 17vh;
min-width: 17vh;
}

View File

@@ -644,6 +644,17 @@ tr {
}
*/
table textarea {
width: 95% !important;
}
table select {
width: 100% !important;
}
table input {
width: 90% !important;
}
button.collapsed {

View File

@@ -160,17 +160,6 @@
min-width: 6vh;
}
textarea {
width: 95% !important;
}
select {
width: 100% !important;
}
input {
width: 90% !important;
}
td > input, td > select, td > textarea, .container-input > input, .container-input > select, .container-input > textarea {
border: 2px solid var(--c_purple);

View File

@@ -57,37 +57,82 @@ th, td {
}
.category {
width: 12%;
#tableMain {
max-width: 90vw;
}
.product {
width: 12%;
#tableMain thead tr th.category, #tableMain tbody tr td.category {
width: 8vh;
min-width: 8vh;
}
.variations {
width: 12%;
}
.currency {
width: 12%;
}
.cost-local-VAT-incl {
width: 10%;
}
.date-puchased, .date-received, .date-unsealed, .date-expiration, .date-consumed {
width: 6%;
}
.storage-location {
width: 12%;
}
.active {
width: 5%;
#tableMain thead tr th.product, #tableMain tbody tr td.product,
#tableMain thead tr th.storage_location, #tableMain tbody tr td.storage_location {
width: 10vh;
min-width: 10vh;
}
.row-new {
visibility: hidden;
#tableMain thead tr th.product_variations.collapsed, #tableMain tbody tr td.product_variations.collapsed {
width: 10vh;
min-width: 10vh;
display: table-cell !important;
}
#tableMain thead tr th.product_variations, #tableMain tbody tr td.product_variations {
width: 20vh;
min-width: 20vh;
}
#tableMain tbody tr td.product_variations table thead tr th, #tableMain tbody tr td.product_variations table tbody tr td {
width: 8vh;
min-width: 8vh;
}
#tableMain tbody tr td.product_variations table thead tr th:last-of-type, #tableMain tbody tr td.product_variations table tbody tr td:last-of-type {
width: 4vh;
min-width: 4vh;
}
textarea, select, input {
width: 100% !important;
#tableMain thead tr th.id_currency_cost.collapsed, #tableMain tbody tr td.id_currency_cost.collapsed {
width: 9vh;
min-width: 9vh;
}
#tableMain thead tr th.id_currency_cost, #tableMain tbody tr td.id_currency_cost {
width: 11vh;
min-width: 11vh;
}
#tableMain thead tr th.cost_local_vat_excl, #tableMain tbody tr td.cost_local_vat_excl,
#tableMain thead tr th.cost_local_vat_incl, #tableMain tbody tr td.cost_local_vat_incl {
width: 9vh;
min-width: 9vh;
}
#tableMain thead tr th.storage-location.collapsed, #tableMain tbody tr td.storage-location.collapsed {
width: 10vh;
min-width: 10vh;
display: table-cell !important;
}
#tableMain thead tr th.storage-location, #tableMain tbody tr td.storage-location {
width: 20vh;
min-width: 20vh;
}
#tableMain tbody tr td.storage-location table thead tr th, #tableMain tbody tr td.storage-location table tbody tr td {
width: 8vh;
min-width: 8vh;
}
#tableMain tbody tr td.storage-location table thead tr th:last-of-type, #tableMain tbody tr td.storage-location table tbody tr td:last-of-type {
width: 4vh;
min-width: 4vh;
}
#tableMain thead tr th.active, #tableMain tbody tr td.active,
#tableMain thead tr th.is_sealed, #tableMain tbody tr td.is_sealed,
#tableMain thead tr th.is_consumed, #tableMain tbody tr td.is_consumed {
width: 6vh;
min-width: 6vh;
}
#tableMain thead tr th.date_purchased, #tableMain tbody tr td.date_purchased,
#tableMain thead tr th.date_received, #tableMain tbody tr td.date_received,
#tableMain thead tr th.date_unsealed, #tableMain tbody tr td.date_unsealed,
#tableMain thead tr th.date_expiration, #tableMain tbody tr td.date_expiration,
#tableMain thead tr th.date_consumed, #tableMain tbody tr td.date_consumed {
width: 17vh;
min-width: 17vh;
}

File diff suppressed because one or more lines are too long

View File

@@ -124,6 +124,21 @@ export default class API {
dataRequest[flagComment] = comment;
return await API.request(hashSaveStoreProductPermutation, 'POST', dataRequest);
}
// stock items
static async getStockItems() {
return await API.request(hashGetStoreStockItem);
}
static async getStockItemsByFilters(filtersJson) {
API.goToHash(hashPageStoreStockItems, filtersJson);
}
static async saveStockItems(stockItems, formFilters, comment) {
let dataRequest = {};
dataRequest[flagFormFilters] = DOM.convertForm2JSON(formFilters);
dataRequest[flagStockItem] = stockItems;
dataRequest[flagComment] = comment;
return await API.request(hashSaveStoreStockItem, 'POST', dataRequest);
}
}
/*

View File

@@ -110,7 +110,7 @@ export default class TableBasePage extends BasePage {
.catch(error => console.error('Error:', error));
}
getFormFilters() {
return document.querySelector(idFormFilters);
return document.querySelector(idFormFilters);
}
callbackLoadTableContent(response) {
let table = this.getTableMain();
@@ -235,13 +235,16 @@ export default class TableBasePage extends BasePage {
});
}
initialiseRowNew(row) {
throw new Error("Subclass of TableBasePage must implement method initialiseRowNew().");
if (this.constructor === TableBasePage) {
throw new Error("Subclass of TableBasePage must implement method initialiseRowNew().");
}
row.classList.remove(flagRowNew);
}
hookupTableMain() {
if (this.constructor === TableBasePage) {
throw new Error("Must implement hookupTableMain() method.");
}
if (_rowBlank == null) {
if (true) { // _rowBlank == null) {
Events.initialiseEventHandler(idTableMain, flagInitialised, (table) => {
this.cacheRowBlank();
});
@@ -445,6 +448,194 @@ export default class TableBasePage extends BasePage {
this.handleClickTableCellDdlPreview(event, td, optionList, cellSelector, (event, element) => { ddlHookup(event, element); });
});
}
hookupProductPermutationVariationFields() {
this.hookupEventHandler("click", idTableMain + ' td.' + flagProductVariations, (event, element) => this.handleClickProductPermutationVariationsPreview(event, element));
}
handleClickProductPermutationVariationsPreview(event, element) {
console.log("click product permutation variations preview");
this.toggleColumnCollapsed(flagProductVariations, false);
let permutationVariations = this.getElementProductVariations(element);
let tblVariations = document.createElement("table");
tblVariations.classList.add(flagProductVariations);
let thead = document.createElement("thead");
let tr = document.createElement("tr");
let thVariationType = document.createElement("th");
thVariationType.textContent = 'Type';
let thNameVariation = document.createElement("th");
thNameVariation.textContent = 'Name';
let buttonAdd = document.createElement("button");
buttonAdd.classList.add(flagAdd);
buttonAdd.textContent = '+';
let thAddDelete = document.createElement("th");
thAddDelete.appendChild(buttonAdd);
tr.appendChild(thVariationType);
tr.appendChild(thNameVariation);
tr.appendChild(thAddDelete);
thead.appendChild(tr);
tblVariations.appendChild(thead);
let tbody = document.createElement("tbody");
console.log('variations:', permutationVariations);
if (Validation.isEmpty(permutationVariations)) {
permutationVariations = [PageStoreProductPermutations.createOptionUnselectedProductVariation()];
}
else {
permutationVariations.forEach((permutationVariation, index) => {
this.addProductPermutationVariationRow(tbody, permutationVariation);
});
}
tblVariations.appendChild(tbody);
let parent = element.parentElement;
parent.innerHTML = '';
parent.appendChild(tblVariations);
console.log("tblVariations: ", tblVariations);
let selectorButtonAdd = idTableMain + ' td.' + flagProductVariations + ' button.' + flagAdd;
this.hookupEventHandler("click", selectorButtonAdd, this.handleClickButtonProductPermutationVariationsAdd);
let selectorButtonDelete = idTableMain + ' td.' + flagProductVariations + ' button.' + flagDelete;
this.hookupEventHandler("click", selectorButtonDelete, this.handleClickButtonProductPermutationVariationsDelete);
}
toggleColumnCollapsed(flagColumn, isCollapsed) {
this.toggleColumnHasClassnameFlag(flagColumn, isCollapsed, flagCollapsed);
}
getElementProductVariations(element) {
let permutationVariations = element.getAttribute(attrValueCurrent);
let objVariations = [];
let parts, new_variation, new_variation_type;
if (!Validation.isEmpty(permutationVariations)) {
permutationVariations = permutationVariations.split(',');
permutationVariations.forEach((variation) => {
parts = variation.split(':');
if (parts.length == 2) {
console.log("parts: ", parts);
new_variation_type = productVariationTypes[parts[0].trim()];
new_variation = productVariations[parts[1].trim()];
objVariations.push({
[flagProductVariationType]: new_variation_type,
[flagProductVariation]: new_variation,
});
}
else {
console.log("error: invalid variation: ", variation);
}
});
}
return objVariations;
}
static createOptionUnselectedProductVariation() {
return {
[flagProductVariationType]: {
[flagNameAttrOptionText]: [flagName],
[flagNameAttrOptionValue]: [attrIdProductVariationType],
[flagName]: 'Select Variation Type',
[attrIdProductVariationType]: 0,
},
[flagProductVariation]: {
[flagNameAttrOptionText]: [flagName],
[flagNameAttrOptionValue]: [attrIdProductVariation],
[flagName]: 'Select Variation',
[attrIdProductVariation]: 0,
},
};
}
addProductPermutationVariationRow(tbody, permutationVariation) {
let productVariationType, optionProductVariationTypeJson, optionProductVariationType, productVariation, optionProductVariationJson, optionProductVariation;
/*
if (Validation.isEmpty(variations)) {
return;
}
*/
let productVariationKeys = Object.keys(productVariations);
let productVariationTypeKeys = Object.keys(productVariationTypes);
console.log("permutationVariation: ", permutationVariation);
let permutationVariationJson = permutationVariation[flagProductVariation];
let permutationVariationTypeJson = permutationVariation[flagProductVariationType];
let tdVariationType = document.createElement("td");
tdVariationType.classList.add(flagProductVariationType);
DOM.setElementAttributesValuesCurrentAndPrevious(tdVariationType, permutationVariationTypeJson[attrIdProductVariationType]);
let ddlVariationType = document.createElement("select");
ddlVariationType.classList.add(flagProductVariationType);
DOM.setElementAttributesValuesCurrentAndPrevious(ddlVariationType, permutationVariationTypeJson[attrIdProductVariationType]);
optionProductVariationType = DOM.createOption(null);
console.log("optionProductVariationType: ", optionProductVariationType);
ddlVariationType.appendChild(optionProductVariationType);
productVariationTypeKeys.forEach((productVariationTypeKey) => {
/*
optionProductVariationType = document.createElement('option');
optionProductVariationType.value = optionVariationType.value;
optionProductVariationType.text = optionVariationType.text;
*/
productVariationType = productVariationTypes[productVariationTypeKey];
optionProductVariationTypeJson = BusinessObjects.getOptionJsonFromObjectJson(productVariationType, permutationVariationTypeJson[attrIdProductVariationType]);
optionProductVariationType = DOM.createOption(optionProductVariationTypeJson);
console.log("optionProductVariationType: ", optionProductVariationType);
ddlVariationType.appendChild(optionProductVariationType);
});
let tdVariation = document.createElement("td");
tdVariation.classList.add(flagProductVariation);
DOM.setElementAttributesValuesCurrentAndPrevious(tdVariation, permutationVariationJson[attrIdProductVariation]);
let ddlVariation = document.createElement("select");
ddlVariation.classList.add(flagProductVariation);
DOM.setElementAttributesValuesCurrentAndPrevious(ddlVariation, permutationVariationJson[attrIdProductVariation]);
optionProductVariation = DOM.createOption(null);
console.log("optionProductVariation: ", optionProductVariation);
ddlVariation.appendChild(optionProductVariation);
productVariationKeys.forEach((productVariationKey) => {
productVariation = productVariations[productVariationKey];
optionProductVariationJson = BusinessObjects.getOptionJsonFromObjectJson(productVariation, permutationVariationJson[attrIdProductVariation]);
optionProductVariation = DOM.createOption(optionProductVariationJson);
console.log("optionProductVariation: ", optionProductVariation);
ddlVariation.appendChild(optionProductVariation);
});
let tdDelete = document.createElement("td");
tdDelete.classList.add(flagDelete);
let buttonDelete = document.createElement("button");
buttonDelete.classList.add(flagDelete);
buttonDelete.textContent = 'x';
let tr = document.createElement("tr");
tdVariationType.appendChild(ddlVariationType);
tr.appendChild(tdVariationType);
tdVariation.appendChild(ddlVariation);
tr.appendChild(tdVariation);
tdDelete.appendChild(buttonDelete);
tr.appendChild(tdDelete);
tbody.appendChild(tr);
}
handleClickButtonProductPermutationVariationsDelete(event, element) {
let row = getRowFromElement(element);
let variationsCell = row.closest('td.' + flagProductVariations);
row.remove();
this.updateProductPermutationVariations(variationsCell);
}
updateProductPermutationVariations(variationsCell) {
let variationPairsString = this.getProductPermutationVariationsText(variationsCell);
variationsCell.setAttribute(attrValueCurrent, variationPairsString);
DOM.isElementDirty(variationsCell);
}
getProductPermutationVariationsText(variationsTd) {
let rows = variationsTd.querySelectorAll('tr');
let variationPairsString = '';
let ddlVariationType, ddlVariation, idVariationType, idVariation;
rows.forEach((row, index) => {
ddlVariationType = row.querySelector('td select.' + flagProductVariationType);
ddlVariation = row.querySelector('td select.' + flagProductVariation);
idVariationType = ddlVariationType.getAttribute(attrValueCurrent);
idVariation = ddlVariation.getAttribute(attrValueCurrent);
variationPairsString += idVariationType + ':' + idVariation + ',';
});
return variationPairsString;
}
leave() {
if (this.constructor === TableBasePage) {
throw new Error("Must implement leave() method.");

View File

@@ -198,7 +198,7 @@ export default class PageStoreProductPermutations extends TableBasePage {
super.hookupTableMain();
this.hookupProductCategoryFields();
this.hookupProductFields();
this.hookupProductVariationFields();
this.hookupProductPermutationVariationFields();
this.hookupDescriptionTextareas();
this.hookupCostFields();
this.hookupLatencyManufactureInputs();
@@ -235,200 +235,12 @@ export default class PageStoreProductPermutations extends TableBasePage {
hookupProductFields() {
this.hookupTableCellDdlPreviews(idTableMain + ' td.' + flagProduct, Utils.getListFromDict(products));
}
hookupProductVariationFields() {
this.hookupEventHandler("click", idTableMain + ' td.' + flagProductVariations + ' div', (event, element) => this.handleClickProductPermutationVariationsPreview(event, element));
}
handleClickProductPermutationVariationsPreview(event, element) {
this.toggleProductPermutationVariationsColumnCollapsed(false);
let permutationVariations = this.getElementProductVariations(element);
let tblVariations = document.createElement("table");
tblVariations.classList.add(flagProductVariations);
let thead = document.createElement("thead");
let tr = document.createElement("tr");
let thVariationType = document.createElement("th");
thVariationType.textContent = 'Type';
let thNameVariation = document.createElement("th");
thNameVariation.textContent = 'Name';
let buttonAdd = document.createElement("button");
buttonAdd.classList.add(flagAdd);
buttonAdd.textContent = '+';
let thAddDelete = document.createElement("th");
thAddDelete.appendChild(buttonAdd);
tr.appendChild(thVariationType);
tr.appendChild(thNameVariation);
tr.appendChild(thAddDelete);
thead.appendChild(tr);
tblVariations.appendChild(thead);
let tbody = document.createElement("tbody");
console.log('variations:', permutationVariations);
if (Validation.isEmpty(permutationVariations)) {
permutationVariations = [PageStoreProductPermutations.createOptionUnselectedProductVariation()];
}
else {
permutationVariations.forEach((permutationVariation, index) => {
this.addProductPermutationVariationRow(tbody, permutationVariation);
});
}
tblVariations.appendChild(tbody);
let parent = element.parentElement;
parent.innerHTML = '';
parent.appendChild(tblVariations);
console.log("tblVariations: ", tblVariations);
let selectorButtonAdd = idTableMain + ' td.' + flagProductVariations + ' button.' + flagAdd;
this.hookupEventHandler("click", selectorButtonAdd, this.handleClickButtonProductPermutationVariationsAdd);
let selectorButtonDelete = idTableMain + ' td.' + flagProductVariations + ' button.' + flagDelete;
this.hookupEventHandler("click", selectorButtonDelete, this.handleClickButtonProductPermutationVariationsDelete);
}
toggleProductPermutationVariationsColumnCollapsed(isCollapsed) {
this.toggleColumnHasClassnameFlag(flagProductVariations, isCollapsed, flagCollapsed);
}
getElementProductVariations(element) {
let permutationVariations = element.getAttribute(attrValueCurrent);
let objVariations = [];
let parts, new_variation, new_variation_type;
if (!Validation.isEmpty(permutationVariations)) {
permutationVariations = permutationVariations.split(',');
permutationVariations.forEach((variation) => {
parts = variation.split(':');
if (parts.length == 2) {
console.log("parts: ", parts);
new_variation_type = productVariationTypes[parts[0].trim()];
new_variation = productVariations[parts[1].trim()];
objVariations.push({
[flagProductVariationType]: new_variation_type,
[flagProductVariation]: new_variation,
});
}
else {
console.log("error: invalid variation: ", variation);
}
});
}
return objVariations;
}
/*
static createOptionUnselectedProductVariation() {
return {
[flagProductVariationType]: {
[flagNameAttrOptionText]: [flagName],
[flagNameAttrOptionValue]: [attrIdProductVariationType],
[flagName]: 'Select Variation Type',
[attrIdProductVariationType]: 0,
},
[flagProductVariation]: {
[flagNameAttrOptionText]: [flagName],
[flagNameAttrOptionValue]: [attrIdProductVariation],
[flagName]: 'Select Variation',
[attrIdProductVariation]: 0,
},
};
}
*/
handleClickButtonProductPermutationVariationsAdd(event, element) {
let row = DOM.getRowFromElement(element);
let tbody = row.querySelector('tbody');
let permutationVariation = PageStoreProductPermutations.createOptionUnselectedProductVariation();
this.addProductPermutationVariationRow(tbody, permutationVariation);
}
addProductPermutationVariationRow(tbody, permutationVariation) {
let productVariationType, optionProductVariationTypeJson, optionProductVariationType, productVariation, optionProductVariationJson, optionProductVariation;
/*
if (Validation.isEmpty(variations)) {
return;
}
*/
let productVariationKeys = Object.keys(productVariations);
let productVariationTypeKeys = Object.keys(productVariationTypes);
console.log("permutationVariation: ", permutationVariation);
let permutationVariationJson = permutationVariation[flagProductVariation];
let permutationVariationTypeJson = permutationVariation[flagProductVariationType];
let tdVariationType = document.createElement("td");
tdVariationType.classList.add(flagProductVariationType);
DOM.setElementAttributesValuesCurrentAndPrevious(tdVariationType, permutationVariationTypeJson[attrIdProductVariationType]);
let ddlVariationType = document.createElement("select");
ddlVariationType.classList.add(flagProductVariationType);
DOM.setElementAttributesValuesCurrentAndPrevious(ddlVariationType, permutationVariationTypeJson[attrIdProductVariationType]);
optionProductVariationType = DOM.createOption(null);
console.log("optionProductVariationType: ", optionProductVariationType);
ddlVariationType.appendChild(optionProductVariationType);
productVariationTypeKeys.forEach((productVariationTypeKey) => {
/*
optionProductVariationType = document.createElement('option');
optionProductVariationType.value = optionVariationType.value;
optionProductVariationType.text = optionVariationType.text;
*/
productVariationType = productVariationTypes[productVariationTypeKey];
optionProductVariationTypeJson = BusinessObjects.getOptionJsonFromObjectJson(productVariationType, permutationVariationTypeJson[attrIdProductVariationType]);
optionProductVariationType = DOM.createOption(optionProductVariationTypeJson);
console.log("optionProductVariationType: ", optionProductVariationType);
ddlVariationType.appendChild(optionProductVariationType);
});
let tdVariation = document.createElement("td");
tdVariation.classList.add(flagProductVariation);
DOM.setElementAttributesValuesCurrentAndPrevious(tdVariation, permutationVariationJson[attrIdProductVariation]);
let ddlVariation = document.createElement("select");
ddlVariation.classList.add(flagProductVariation);
DOM.setElementAttributesValuesCurrentAndPrevious(ddlVariation, permutationVariationJson[attrIdProductVariation]);
optionProductVariation = DOM.createOption(null);
console.log("optionProductVariation: ", optionProductVariation);
ddlVariation.appendChild(optionProductVariation);
productVariationKeys.forEach((productVariationKey) => {
productVariation = productVariations[productVariationKey];
optionProductVariationJson = BusinessObjects.getOptionJsonFromObjectJson(productVariation, permutationVariationJson[attrIdProductVariation]);
optionProductVariation = DOM.createOption(optionProductVariationJson);
console.log("optionProductVariation: ", optionProductVariation);
ddlVariation.appendChild(optionProductVariation);
});
let tdDelete = document.createElement("td");
tdDelete.classList.add(flagDelete);
let buttonDelete = document.createElement("button");
buttonDelete.classList.add(flagDelete);
buttonDelete.textContent = 'x';
let tr = document.createElement("tr");
tdVariationType.appendChild(ddlVariationType);
tr.appendChild(tdVariationType);
tdVariation.appendChild(ddlVariation);
tr.appendChild(tdVariation);
tdDelete.appendChild(buttonDelete);
tr.appendChild(tdDelete);
tbody.appendChild(tr);
}
handleClickButtonProductPermutationVariationsDelete(event, element) {
let row = getRowFromElement(element);
let variationsCell = row.closest('td.' + flagProductVariations);
row.remove();
this.updateProductPermutationVariations(variationsCell);
}
updateProductPermutationVariations(variationsCell) {
let variationPairsString = this.getProductPermutationVariationsText(variationsCell);
variationsCell.setAttribute(attrValueCurrent, variationPairsString);
DOM.isElementDirty(variationsCell);
}
getProductPermutationVariationsText(variationsTd) {
let rows = variationsTd.querySelectorAll('tr');
let variationPairsString = '';
let ddlVariationType, ddlVariation, idVariationType, idVariation;
rows.forEach((row, index) => {
ddlVariationType = row.querySelector('td select.' + flagProductVariationType);
ddlVariation = row.querySelector('td select.' + flagProductVariation);
idVariationType = ddlVariationType.getAttribute(attrValueCurrent);
idVariation = ddlVariation.getAttribute(attrValueCurrent);
variationPairsString += idVariationType + ':' + idVariation + ',';
});
return variationPairsString;
}
hookupDescriptionTextareas() {
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagDescription + ' textarea');
@@ -495,7 +307,6 @@ export default class PageStoreProductPermutations extends TableBasePage {
let divOrDdlIntervalRecurrence = row.querySelector('td.' + flagUnitMeasurementIntervalRecurrence + ' .' + flagUnitMeasurementIntervalRecurrence);
if (isSubscription) {
inputCountIntervalRecurrence.classList.remove(flagCollapsed);
DOM.setElementValueCurrentIfEmpty(inputCountIntervalRecurrence, 1);
divOrDdlIntervalRecurrence.classList.remove(flagCollapsed);
let tdUnitMeasurementIntervalRecurrence = divOrDdlIntervalRecurrence.closest('td');
tdUnitMeasurementIntervalRecurrence.dispatchEvent(new Event('click'));
@@ -528,7 +339,6 @@ export default class PageStoreProductPermutations extends TableBasePage {
let divOrDdlIntervalExpirationUnsealed = row.querySelector('td.' + flagUnitMeasurementIntervalExpirationUnsealed + ' .' + flagUnitMeasurementIntervalExpirationUnsealed);
if (doesExpireFasterOnceUnsealed) {
inputCountIntervalExpirationUnsealed.classList.remove(flagCollapsed);
DOM.setElementValueCurrentIfEmpty(inputCountIntervalExpirationUnsealed, 1);
divOrDdlIntervalExpirationUnsealed.classList.remove(flagCollapsed);
let tdUnitMeasurementIntervalExpirationUnsealed = divOrDdlIntervalExpirationUnsealed.closest('td');
tdUnitMeasurementIntervalExpirationUnsealed.dispatchEvent(new Event('click'));

View File

@@ -1,508 +1,367 @@
import API from "../../api.js";
import BusinessObjects from "../../lib/business_objects.js";
import DOM from "../../dom.js";
import Events from "../../lib/events.js";
import TableBasePage from "../base_table.js";
import Utils from "../../lib/utils.js";
import Validation from "../../lib/validation.js";
import BasePage from "../base.js";
import StoreTableMixinPage from "./mixin_table.js";
export default class PageStoreStockItems extends BasePage {
export default class PageStoreStockItems extends TableBasePage {
static hash = hashPageStoreStockItems;
callFilterTableContent = API.getStockItemsByFilters;
callSaveTableContent = API.saveStockItems;
constructor(router) {
super(router);
this.storeMixin = new StoreTableMixinPage(this);
}
initialize() {
this.sharedInitialize();
this.hookupFilters();
this.hookupButtonsSaveCancel();
hookupTableMain();
hookupOverlayConfirm(savePermutations);
}
hookupFilters() {
let filterCategory = document.querySelectorAll(idFilterCategory);
Events.initialiseEventHandler(filterCategory, flagInitialised, function() {
console.log("hooking up filter category");
filterCategory = document.querySelectorAll(filterCategory);
/*
listCategories.forEach(function(category) {
console.log('adding category: ', category.value, category.text);
/*
let option = document.createElement('option');
option.value = category.value;
option.text = category.text;
*
filterCategory.appendChild(document.createElement('<option>', category));
});
console.log(listCategories);
*/
filterCategory.addEventListener("change", function(event) {
loadPermutations();
});
console.log("hooked up filter category");
});
let filterProduct = document.querySelectorAll(idFilterProduct);
Events.initialiseEventHandler(filterProduct, flagInitialised, function() {
listProducts.forEach(function(product) {
if (product[attrIdProductCategory] != DOM.getElementValueCurrent(document.querySelectorAll(idFilterCategory))) return;
/*
let option = document.createElement('option');
option.value = product.value;
option.text = product.text;
*/
filterProduct.appendChild(document.createElement('<option>', product));
});
filterProduct.addEventListener("change", function(event) {
loadPermutations();
});
});
let filterIsOutOfStock = document.querySelectorAll(idFilterIsOutOfStock);
Events.initialiseEventHandler(filterIsOutOfStock, flagInitialised, function() {
filterIsOutOfStock.addEventListener("change", function(event) {
loadPermutations();
});
});
let filterQuantityMin = document.querySelectorAll(idFilterQuantityMin);
Events.initialiseEventHandler(filterQuantityMin, flagInitialised, function() {
filterQuantityMin.addEventListener("change", function(event) {
loadPermutations();
});
});
let filterQuantityMax = document.querySelectorAll(idFilterQuantityMax);
Events.initialiseEventHandler(filterQuantityMax, flagInitialised, function() {
filterQuantityMax.addEventListener("change", function(event) {
loadPermutations();
this.sharedHookupFilters();
this.hookupFilterProductCategory();
this.hookupFilterProduct();
this.hookupFilterOutOfStock();
this.hookupFilterMinStock();
this.hookupFilterMaxStock();
}
hookupFilterProductCategory() {
this.hookupFilter(flagProductCategory, (event, filterCategory) => {
// loadPermutations();
// let wasDirtyFilter = filterCategory.classList.contains(flagDirty);
PageStoreStockItems.isDirtyFilter(filterCategory);
let isDirtyFilter = filterCategory.classList.contains(flagDirty);
let idProductCategory = DOM.getElementValueCurrent(filterCategory);
let products = productCategories[idProductCategory];
let filterProduct = document.querySelector(idFormFilters + ' .' + flagProduct);
let idProductPrevious = filterProduct.getAttribute(attrValuePrevious);
filterProduct.innerHTML = '';
let optionJson, option;
option = DOM.createOption(null);
filterProduct.appendChild(option);
products.forEach((product) => {
optionJson = BusinessObjects.getOptionJsonFromObjectJson(product, idProductPrevious);
option = DOM.createOption(optionJson);
filterProduct.appendChild(option);
});
filterProduct.dispatchEvent(new Event('change'));
});
}
loadPermutations() {
let elForm = document.querySelectorAll(idFormFiltersPermutations);
let ajaxData = {};
ajaxData[keyForm] = convertForm2JSON(elForm);
ajaxData.csrf_token = ajaxData[keyForm].csrf_token;
/*
ajaxData[attrIdProductCategory] = DOM.getElementValueCurrent(document.querySelectorAll(idFilterCategory));
ajaxData[attrIdProduct] = DOM.getElementValueCurrent(document.querySelectorAll(idFilterProduct));
ajaxData[flagIsOutOfStock] = DOM.getElementValueCurrent(document.querySelectorAll(idFilterIsOutOfStock));
ajaxData[flagQuantityMin] = DOM.getElementValueCurrent(document.querySelectorAll(idFilterQuantityMin));
ajaxData[flagQuantityMax] = DOM.getElementValueCurrent(document.querySelectorAll(idFilterQuantityMax));
*/
console.log('ajaxData:'); console.log(ajaxData);
ajaxJSONData('permutations', mapHashToController(hashPageStorePermutationsPost), ajaxData, callbackLoadPermutations, false, {"X-CSRFToken": ajaxData.csrf_token});
hookupFilterProduct() {
this.hookupFilter(flagProduct);
}
callbackLoadPermutations(response) {
console.log('ajax:'); console.log(response.data);
let table = document.querySelectorAll(idTableMain);
let bodyTable, row, dllCategory, ddlProduct;
// table.querySelector('tr').remove(); // :not(.' + flagRowNew + ')
bodyTable = table.querySelector('tbody');
bodyTable.querySelector('tr').remove();
$.each(response.data, function(_, dataRow) {
row = _rowBlank.cloneNode(true);
row = document.querySelectorAll(row);
row.classList.remove(flagRowNew);
console.log("applying data row: ", dataRow);
dllCategory = row.querySelector('td.' + flagProductCategory + ' select');
dllCategory.val(dataRow[attrIdProductCategory]);
ddlProduct = row.querySelector('td.' + flagProduct + ' select');
listProducts.forEach(function(product) {
if (product[attrIdProductCategory] != dataRow[attrIdProductCategory]) return;
ddlProduct.appendChild(document.createElement('<option>', product));
});
ddlProduct.val(dataRow[attrIdProduct]);
row.querySelector('td.' + flagProductVariations + ' textarea').value = dataRow[flagProductVariations];
row.querySelector('td.' + flagQuantityStock + ' input').value = dataRow[flagQuantityStock];
row.querySelector('td.' + flagQuantityMin + ' input').value = dataRow[flagQuantityMin];
row.querySelector('td.' + flagQuantityMax + ' input').value = dataRow[flagQuantityMax];
row.querySelector('td.' + flagCostLocal).innerHTML = dataRow[flagCostLocal];
row.setAttribute(attrIdProductCategory, dataRow[flagProductCategory]);
row.setAttribute(attrIdProduct, dataRow[flagProduct]);
row.setAttribute(attrIdPermutation, dataRow[attrIdPermutation]);
bodyTable.appendChild(row);
});
hookupFilterOutOfStock() {
this.hookupFilter(flagIsOutOfStock);
}
hookupButtonsSaveCancel() {
let btnSave = document.querySelectorAll(idButtonSave);
let btnCancel = document.querySelectorAll(idButtonCancel);
let btnAdd = document.querySelectorAll(idButtonAdd);
btnSave.addEventListener("click", function(event) {
event.stopPropagation();
showOverlayConfirm();
});
btnSave.classList.add(flagCollapsed);
btnCancel.addEventListener("click", function(event) {
event.stopPropagation();
loadPermutations();
});
btnCancel.classList.add(flagCollapsed);
btnAdd.addEventListener("click", function(event) {
event.stopPropagation();
let table = document.querySelectorAll(idTableMain);
let row = _rowBlank.cloneNode(true);
row = document.querySelectorAll(row);
row.classList.remove(flagRowNew);
table.querySelector('tbody').appendChild(row);
});
hookupFilterMinStock() {
this.hookupFilter(flagQuantityMin);
}
savePermutations() {
let permutations = getPermutations(true);
if (permutations.length == 0) {
showOverlayError('No permutations to save');
return;
}
let ajaxData = {};
ajaxData[keyPermutations] = permutations;
ajaxData[keyForm] = convertForm2JSON(elForm);
ajaxData.csrf_token = ajaxData[keyForm].csrf_token;
ajaxData.comment = document.querySelector(idTextareaConfirm).value;
console.log('ajaxData:'); console.log(ajaxData);
ajaxJSONData('permutations', mapHashToController(hashPageStorePermutationsPost), ajaxData, callbackLoadPermutations, false, {});
}
getPermutations(dirtyOnly) {
let table = document.querySelectorAll(idTableMain);
let permutations = [];
let row, permutation, ddlCategory, ddlProduct, variations, quantityStock, quantityMin, quantityMax, costLocal;
table.querySelector('tbody tr').each(function(index, row) {
row = document.querySelectorAll(row);
if (dirtyOnly && !row.classList.contains(flagDirty)) return;
ddlCategory = row.querySelector('td.' + flagProductCategory + ' select');
ddlProduct = row.querySelector('td.' + flagProduct + ' select');
variations = row.querySelector('td.' + flagProductVariations + ' textarea');
quantityStock = row.querySelector('td.' + flagQuantityStock + ' input');
quantityMin = row.querySelector('td.' + flagQuantityMin + ' input');
quantityMax = row.querySelector('td.' + flagQuantityMax + ' input');
permutation = {};
permutation[attrIdProductCategory] = ddlCategory.getAttribute(attrValueCurrent);
permutation[attrIdProduct] = ddlProduct.getAttribute(attrValueCurrent);
permutation[attrIdPermutation] = row.getAttribute(attrIdPermutation)
permutation[flagProductVariations] = variations.getAttribute(attrValueCurrent);
permutation[flagQuantityStock] = quantityStock.getAttribute(attrValueCurrent);
permutation[flagQuantityMin] = quantityMin.getAttribute(attrValueCurrent);
permutation[flagQuantityMax] = quantityMax.getAttribute(attrValueCurrent);
permutations.push(permutation);
});
return permutations;
}
hookupTableMain() {
let table = document.querySelectorAll(idTableMain);
let rowBlankTemp = table.querySelector('tr.' + flagRowNew);
console.log("row blank temp: ", rowBlankTemp);
_rowBlank = rowBlankTemp.cloneNode(true);
table.querySelector('tr.' + flagRowNew).remove();
/*
let ddlCategory, ddlProduct;
let optionsCategory = document.querySelectorAll(idFilterCategory + ' option');
optionsCategory.
console.log('optionsCategory:', optionsCategory);
table.querySelector('tbody tr').each(function(index, row) {
console.log("hooking up row ", index);
row = document.querySelectorAll(row);
ddlCategory = row.querySelector('td.' + flagProductCategory + ' select');
ddlProduct = row.querySelector('td.' + flagProduct + ' select');
optionsCategory.clone().appendTo(ddlCategory);
/*
listProducts.forEach(function(product) {
if (product[attrIdProductCategory] != DOM.getElementValueCurrent(ddlCategory)) return;
ddlProduct.appendChild(document.createElement('<option>', product));
});
*
});
*/
let ddlCategory, ddlProduct, variations, quantityStock, quantityMin, quantityMax, costLocal;
table.querySelector('tbody tr').each(function(index, row) {
console.log("hooking up row ", index);
row = document.querySelectorAll(row);
ddlCategory = row.querySelector('td.' + flagProductCategory + ' select');
ddlProduct = row.querySelector('td.' + flagProduct + ' select');
variations = row.querySelector('td.' + flagProductVariations + ' textarea');
quantityStock = row.querySelector('td.' + flagQuantityStock + ' input');
quantityMin = row.querySelector('td.' + flagQuantityMin + ' input');
quantityMax = row.querySelector('td.' + flagQuantityMax + ' input');
Events.initialiseEventHandler(ddlCategory, flagInitialised, function() {
// ddlCategory = document.querySelectorAll(ddlCategory);
ddlCategory.addEventListener('change', function() {
/*
ddlCategory.setAttribute(attrValuePrevious, ddlCategory.getAttribute(attrValueCurrent));
ddlCategory.setAttribute(attrValueCurrent, ddlCategory.val());
*/
handleChangeInputPermutations(this);
ddlCategory = this;
row = getRowFromElement(ddlCategory);
ddlProduct = row.querySelector('td.' + flagProduct + ' select');
// ddlProduct = document.querySelectorAll(ddlProduct);
ddlProduct.querySelector('option').remove();
ddlProduct.appendChild(document.createElement('<option>', {value: '', text: 'Select Product'}));
listProducts.forEach(function(product) {
if (product[attrIdProductCategory] != DOM.getElementValueCurrent(ddlCategory)) return;
ddlProduct.appendChild(document.createElement('<option>', product));
});
handleChangeInputPermutations(ddlProduct);
});
});
Events.initialiseEventHandler(ddlProduct, flagInitialised, function() {
// ddlProduct = document.querySelectorAll(ddlProduct);
ddlProduct.addEventListener('change', function() {
handleChangeInputPermutations(this);
});
});
Events.initialiseEventHandler(variations, flagInitialised, function() {
// variations = document.querySelectorAll(variations);
variations.addEventListener('change', function() {
handleChangeInputPermutations(this);
});
});
Events.initialiseEventHandler(quantityStock, flagInitialised, function() {
// quantityStock = document.querySelectorAll(quantityStock);
quantityStock.addEventListener('change', function() {
// console.log(this.value);
// quantityStock.value = this.value;
handleChangeInputPermutations(this);
});
});
Events.initialiseEventHandler(quantityMin, flagInitialised, function() {
// quantityMin = document.querySelectorAll(quantityMin);
quantityMin.addEventListener('change', function() {
handleChangeInputPermutations(this);
});
});
Events.initialiseEventHandler(quantityMax, flagInitialised, function() {
// quantityMax = document.querySelectorAll(quantityMax);
quantityMax.addEventListener('change', function() {
handleChangeInputPermutations(this);
});
});
});
}
handleChangeInputPermutations(element) {
console.log(element.value);
let objJQuery = document.querySelectorAll(element);
objJQuery.value = element.value;
let row = getRowFromElement(objJQuery);
let buttonCancel = document.querySelectorAll(idButtonCancel);
let buttonSave = document.querySelectorAll(idButtonSave);
let wasDirty = updateAndCheckIsElementDirty(objJQuery);
if (objJQuery.classList.contains(flagProductVariations)) {
objJQuery.setAttribute(attrValueCurrent, getVariationsCurrentValue(objJQuery));
} else {
objJQuery.setAttribute(attrValueCurrent, DOM.getElementValueCurrent(objJQuery));
}
let isDirty = updateAndCheckIsElementDirty(objJQuery);
if (wasDirty != isDirty) {
isRowDirty(row);
let permutationsDirty = getPermutations(true);
if (Validation.isEmpty(permutationsDirty)) {
buttonCancel.classList.add(flagCollapsed);
buttonSave.classList.add(flagCollapsed);
} else {
buttonCancel.classList.remove(flagCollapsed);
buttonSave.classList.remove(flagCollapsed);
}
}
}
isRowDirty(row) {
let ddlCategory = row.querySelector('td.' + flagProductCategory + ' select');
let ddlProduct = row.querySelector('td.' + flagProduct + ' select');
let variations = row.querySelector('td.' + flagProductVariations + ' textarea');
let quantityStock = row.querySelector('td.' + flagQuantityStock + ' input');
let quantityMin = row.querySelector('td.' + flagQuantityMin + ' input');
let quantityMax = row.querySelector('td.' + flagQuantityMax + ' input');
// return updateAndCheckIsElementDirty(ddlCategory) || updateAndCheckIsElementDirty(ddlProduct) || updateAndCheckIsElementDirty(variations) || updateAndCheckIsElementDirty(quantityStock) || updateAndCheckIsElementDirty(quantityMin) || updateAndCheckIsElementDirty(quantityMax);
let isDirty = ddlCategory.classList.contains(flagDirty) || ddlProduct.classList.contains(flagDirty) || variations.classList.contains(flagDirty) ||
quantityStock.classList.contains(flagDirty) || quantityMin.classList.contains(flagDirty) || quantityMax.classList.contains(flagDirty);
if (isDirty) {
row.classList.add(flagDirty);
} else {
row.classList.remove(flagDirty);
}
return isDirty;
}
getVariationsCurrentValue(element) {
let value = element.value || null;
let variations = value.split('\n');
variations = variations.map(function(variation) {
return variation.trim();
});
variations = variations.filter(function(variation) {
return variation.length > 0;
});
return variations.join(',');
}
}
import TableBasePage from "../base_table.js";
import API from "../../api.js";
import DOM from "../../dom.js";
export class PageStoreProductCategories extends TableBasePage {
static hash = hashPageStoreProductCategories;
callFilterTableContent = API.getCategoriesByFilters;
constructor() {
super();
}
initialize() {
super.initialize();
}
hookupFilters() {
super.hookupFilters();
this.hookupFilterIsNotEmpty();
this.hookupFilterActive();
}
hookupFilterIsNotEmpty() {
Events.initialiseEventHandler('.' + flagIsNotEmpty, flagInitialised, (filter) => {
filter.addEventListener("change", (event) => {
PageStoreProductCategories.isDirtyFilter(filter);
});
});
hookupFilterMaxStock() {
this.hookupFilter(flagQuantityMax);
}
loadRowTable(rowJson) {
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 textareaCode = row.querySelector('td.' + flagCode + ' textarea');
let textareaName = row.querySelector('td.' + flagName + ' textarea');
let textareaDescription = row.querySelector('td.' + flagDescription + ' textarea');
let tdAccessLevel = row.querySelector('td.' + flagAccessLevel);
let divAccessLevel = tdAccessLevel.querySelector('div.' + flagAccessLevel);
let inputActive = row.querySelector('td.' + flagActive + ' input[type="checkbox"]');
sliderDisplayOrder.setAttribute(attrValueCurrent, rowJson[flagDisplayOrder]);
DOM.setElementAttributeValuePrevious(sliderDisplayOrder, rowJson[flagDisplayOrder]);
DOM.setElementValueCurrent(textareaCode, rowJson[flagCode]);
DOM.setElementAttributeValuePrevious(textareaCode, rowJson[flagCode]);
DOM.setElementValueCurrent(textareaName, rowJson[flagName]);
DOM.setElementAttributeValuePrevious(textareaName, rowJson[flagName]);
DOM.setElementValueCurrent(textareaDescription, rowJson[flagDescription]);
DOM.setElementAttributeValuePrevious(textareaDescription, rowJson[flagDescription]);
tdAccessLevel.setAttribute(attrIdAccessLevel, rowJson[attrIdAccessLevel]);
tdAccessLevel.setAttribute(flagAccessLevelRequired, rowJson[flagAccessLevelRequired]);
divAccessLevel.setAttribute(attrIdAccessLevel, rowJson[attrIdAccessLevel]);
DOM.setElementValueCurrent(divAccessLevel, rowJson[attrIdAccessLevel]);
DOM.setElementAttributeValuePrevious(divAccessLevel, rowJson[attrIdAccessLevel]);
divAccessLevel.textContent = rowJson[flagAccessLevelRequired];
DOM.setElementValueCurrent(inputActive, rowJson[flagActive]);
DOM.setElementAttributeValuePrevious(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 textareaCode = row.querySelector('td.' + flagCode + ' textarea');
let textareaName = row.querySelector('td.' + flagName + ' textarea');
let textareaDescription = row.querySelector('td.' + flagDescription + ' textarea');
let tdAccessLevel = row.querySelector('td.' + flagAccessLevel);
let inputActive = row.querySelector('td.' + flagActive + ' input[type="checkbox"]');
let tdProductCategory = row.querySelector('td.' + flagProductCategory);
let tdProduct = row.querySelector('td.' + flagProduct);
let tdProductVariations = row.querySelector('td.' + flagProductVariations);
let tdCurrencyCost = row.querySelector('td.' + flagCurrencyCost);
let inputCostLocalVatExcl = row.querySelector('td.' + flagCostLocalVatExcl + ' input');
let inputCostLocalVatIncl = row.querySelector('td.' + flagCostLocalVatIncl + ' input');
let inputDatePurchased = row.querySelector('td.' + flagDatePurchased + ' input');
let inputDateReceived = row.querySelector('td.' + flagDateReceived + ' input');
let tdStorageLocation = row.querySelector('td.' + flagStorageLocation);
let inputIsSealed = row.querySelector('td.' + flagIsSealed + ' input');
let inputDateUnsealed = row.querySelector('td.' + flagDateUnsealed + ' input');
let inputDateExpiration = row.querySelector('td.' + flagDateExpiration + ' input');
let inputIsConsumed = row.querySelector('td.' + flagIsConsumed + ' input');
let inputDateConsumed = row.querySelector('td.' + flagDateConsumed + ' input');
let checkboxActive = row.querySelector('td.' + flagActive + ' input');
let jsonCategory = {};
jsonCategory[attrIdProductCategory] = row.getAttribute(attrIdProductCategory);
jsonCategory[flagCode] = DOM.getElementValueCurrent(textareaCode);
jsonCategory[flagName] = DOM.getElementValueCurrent(textareaName);
jsonCategory[flagDescription] = DOM.getElementValueCurrent(textareaDescription);
jsonCategory[flagAccessLevelRequired] = tdAccessLevel.getAttribute(flagAccessLevelRequired);
jsonCategory[attrIdAccessLevel] = tdAccessLevel.getAttribute(attrIdAccessLevel);
jsonCategory[flagActive] = DOM.getElementValueCurrent(inputActive);
jsonCategory[flagDisplayOrder] = sliderDisplayOrder.getAttribute(attrValueCurrent);
return jsonCategory;
let jsonRow = {};
jsonRow[attrIdStockItem] = row.getAttribute(attrIdStockItem);
jsonRow[attrIdProductPermutation] = tdProductVariations.getAttribute(attrIdProductPermutation);
jsonRow[attrIdProductCategory] = DOM.getElementAttributeValueCurrent(tdProductCategory);
jsonRow[attrIdProduct] = DOM.getElementAttributeValueCurrent(tdProduct);
jsonRow[flagProductVariations] = DOM.getElementAttributeValueCurrent(tdProductVariations);
jsonRow[flagHasVariations] = jsonRow[flagProductVariations] != '';
jsonRow[flagCurrencyCost] = DOM.getElementAttributeValueCurrent(tdCurrencyCost);
jsonRow[flagCostLocalVatExcl] = DOM.getElementAttributeValueCurrent(inputCostLocalVatExcl);
jsonRow[flagCostLocalVatIncl] = DOM.getElementAttributeValueCurrent(inputCostLocalVatIncl);
jsonRow[flagDatePurchased] = DOM.getElementAttributeValueCurrent(inputDatePurchased);
jsonRow[flagDateReceived] = DOM.getElementAttributeValueCurrent(inputDateReceived);
jsonRow[attrIdStorageLocation] = DOM.getElementAttributeValueCurrent(tdStorageLocation);
jsonRow[flagIsSealed] = DOM.getElementAttributeValueCurrent(inputIsSealed);
jsonRow[flagDateUnsealed] = DOM.getElementAttributeValueCurrent(inputDateUnsealed);
jsonRow[flagDateExpiration] = DOM.getElementAttributeValueCurrent(inputDateExpiration);
jsonRow[flagIsConsumed] = DOM.getElementAttributeValueCurrent(inputIsConsumed);
jsonRow[flagDateConsumed] = DOM.getElementAttributeValueCurrent(inputDateConsumed);
jsonRow[flagActive] = checkboxActive.getAttribute(attrValueCurrent);
return jsonRow;
}
initialiseRowNew(row) {
super.initialiseRowNew(row);
let ddlCategoryFilter = document.querySelector(idFormFilters + ' #' + attrIdProductCategory);
let idProductCategoryFilter = DOM.getElementValueCurrent(ddlCategoryFilter);
let hasCategoryFilter = !(Validation.isEmpty(idProductCategoryFilter) || idProductCategoryFilter == '0');
let ddlProductFilter = document.querySelector(idFormFilters + ' #' + attrIdProduct);
let idProductFilter = DOM.getElementValueCurrent(ddlProductFilter);
let hasProductFilter = !(Validation.isEmpty(idProductFilter) || idProductFilter == '0');
console.log("initialiseRowNew: ", row);
console.log({ddlCategoryFilter, idProductCategoryFilter, hasCategoryFilter, ddlProductFilter, idProductFilter, hasProductFilter});
if (!hasCategoryFilter && !hasProductFilter) return;
if (hasCategoryFilter) {
let ddlCategory = row.querySelector('td.' + flagProductCategory + ' select');
DOM.setElementValuesCurrentAndPrevious(ddlCategory, idProductCategoryFilter);
this.handleChangeProductCategoryDdl(null, ddlCategory);
}
if (hasProductFilter) {
let ddlProduct = row.querySelector('td.' + flagProduct + ' select');
DOM.setElementValuesCurrentAndPrevious(ddlProduct, idProductFilter);
}
}
hookupTableMain() {
super.hookupTableMain();
this.hookupSlidersDisplayOrderTable();
this.hookupTextareasCodeTable();
this.hookupTextareasNameTable();
this.hookupTextareasDescriptionTable();
this.hookupTdsAccessLevel();
this.hookupInputsActiveTable();
this.hookupProductCategoryFields();
this.hookupProductFields();
this.hookupProductPermutationVariationFields();
this.hookupCurrencyCostFields();
this.hookupCostInputs();
this.hookupOrderDateInputs();
this.hookupStorageLocationFields();
this.hookupSealingInputs();
this.hookupExpirationDateInputs();
this.hookupConsumationInputs();
this.hookupActiveCheckboxes();
}
isRowDirty(row) {
if (row == null) return;
let ddlCategory = row.querySelector('td.' + flagProductCategory + ' select');
hookupProductCategoryFields() {
this.hookupTableCellDdlPreviews(idTableMain + ' td.' + flagProductCategory, Utils.getListFromDict(productCategories), (event, element) => { this.hookupProductCategoryDdls(event, element); });
}
hookupProductCategoryDdls(ddlSelector) {
this.hookupChangeHandlerTableCells(ddlSelector, (event, element) => { this.handleChangeProductCategoryDdl(event, element); });
}
handleChangeProductCategoryDdl(event, ddlCategory) {
this.handleChangeTableCellDdl(event, ddlCategory);
let idProductCategorySelected = DOM.getElementValueCurrent(ddlCategory);
let row = DOM.getRowFromElement(ddlCategory);
let tdProduct = row.querySelector('td.' + flagProduct);
tdProduct.dispatchEvent(new Event('click'));
let ddlProduct = row.querySelector('td.' + flagProduct + ' select');
let variations = row.querySelector('td.' + flagProductVariations + ' textarea');
let quantityStock = row.querySelector('td.' + flagQuantityStock + ' input');
let quantityMin = row.querySelector('td.' + flagQuantityMin + ' input');
let quantityMax = row.querySelector('td.' + flagQuantityMax + ' input');
// return updateAndCheckIsElementDirty(ddlCategory) || updateAndCheckIsElementDirty(ddlProduct) || updateAndCheckIsElementDirty(variations) || updateAndCheckIsElementDirty(quantityStock) || updateAndCheckIsElementDirty(quantityMin) || updateAndCheckIsElementDirty(quantityMax);
let isDirty = ddlCategory.classList.contains(flagDirty) || ddlProduct.classList.contains(flagDirty) || variations.classList.contains(flagDirty) ||
quantityStock.classList.contains(flagDirty) || quantityMin.classList.contains(flagDirty) || quantityMax.classList.contains(flagDirty);
if (isDirty) {
row.classList.add(flagDirty);
} else {
row.classList.remove(flagDirty);
}
return isDirty;
ddlProduct.innerHTML = '';
ddlProduct.appendChild(DOM.createOption(null));
let optionJson, option;
Utils.getListFromDict(products).forEach((product) => {
if (product[attrIdProductCategory] != idProductCategorySelected) return;
optionJson = BusinessObjects.getOptionJsonFromObjectJson(product);
option = DOM.createOption(optionJson);
ddlProduct.appendChild(option);
});
this.handleChangeTableCellDdl(event, ddlProduct);
}
hookupProductFields() {
this.hookupTableCellDdlPreviews(idTableMain + ' td.' + flagProduct, Utils.getListFromDict(products));
}
handleClickProductPermutationVariationsPreview(event, element) {
let row = DOM.getRowFromElement(element);
let tdProduct = row.querySelector('td.' + flagProduct);
let idProduct = DOM.getElementValueCurrent(tdProduct);
let product = products[idProduct];
if (!product[flagHasVariations]) return;
super.handleClickProductPermutationVariationsPreview(event, element);
}
handleClickButtonProductPermutationVariationsAdd(event, element) {
let row = DOM.getRowFromElement(element);
let tbody = row.querySelector('tbody');
let permutationVariation = PageStoreStockItems.createOptionUnselectedProductVariation();
this.addProductPermutationVariationRow(tbody, permutationVariation);
}
hookupCurrencyCostFields(){
this.hookupTableCellDdlPreviews(idTableMain + ' td.' + flagCurrencyCost, Utils.getListFromDict(currencies));
}
hookupCostInputs(){
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagCostLocalVatExcl + ' input');
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagCostLocalVatIncl + ' input');
}
hookupOrderDateInputs(){
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagDatePurchased + ' input');
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagDateReceived + ' input');
}
hookupStorageLocationFields(){
this.hookupEventHandler(
"click",
idTableMain + ' td.' + flagStorageLocation,
(event, element) => this.handleClickStorageLocationPreview(event, element)
);
}
handleClickStorageLocationPreview(event, element) {
this.toggleColumnCollapsed(flagStorageLocation, false);
let idPlant = element.getAttribute(attrIdPlant);
let idStorageLocation = element.getAttribute(attrIdStorageLocation);
let tblStorageLocation = document.createElement("table");
tblStorageLocation.classList.add(flagProductVariations);
let thead = document.createElement("thead");
let thPlant = document.createElement("th");
thPlant.textContent = 'Plant';
let thLocation = document.createElement("th");
thLocation.textContent = 'Location';
let trHead = document.createElement("tr");
trHead.appendChild(thPlant);
trHead.appendChild(thLocation);
thead.appendChild(trHead);
tblStorageLocation.appendChild(thead);
let tbody = document.createElement("tbody");
let plant, optionPlantJson, optionPlant, storageLocation, optionStorageLocationJson, optionStorageLocation;
let plantKeys = Object.keys(plants);
let storageLocationKeys = Object.keys(storageLocations);
let plantJson = plants[idPlant];
let storageLocationJson = storageLocations[idStorageLocation];
let tdPlant = document.createElement("td");
tdPlant.classList.add(flagPlant);
DOM.setElementAttributesValuesCurrentAndPrevious(tdPlant, plantJson[attrIdPlant]);
let ddlPlant = document.createElement("select");
ddlPlant.classList.add(flagPlant);
DOM.setElementAttributesValuesCurrentAndPrevious(ddlPlant, plantJson[attrIdPlant]);
optionPlant = DOM.createOption(null);
console.log("optionPlant: ", optionPlant);
ddlPlant.appendChild(optionPlant);
plantKeys.forEach((plantKey) => {
plant = plants[plantKey];
optionPlantJson = BusinessObjects.getOptionJsonFromObjectJson(
objectJson = plant,
valueSelected = plantJson[attrIdPlant]
);
optionPlant = DOM.createOption(optionPlantJson);
console.log("optionPlant: ", optionPlant);
ddlPlant.appendChild(optionPlant);
});
let tdStorageLocation = document.createElement("td");
tdStorageLocation.classList.add(flagStorageLocation);
DOM.setElementAttributesValuesCurrentAndPrevious(tdStorageLocation, storageLocationJson[attrIdStorageLocation]);
let ddlStorageLocation = document.createElement("select");
ddlStorageLocation.classList.add(flagStorageLocation);
DOM.setElementAttributesValuesCurrentAndPrevious(ddlStorageLocation, storageLocationJson[attrIdStorageLocation]);
optionStorageLocation = DOM.createOption(null);
console.log("optionStorageLocation: ", optionStorageLocation);
ddlStorageLocation.appendChild(optionStorageLocation);
StorageLocationKeys.forEach((StorageLocationKey) => {
storageLocation = StorageLocations[StorageLocationKey];
optionStorageLocationJson = BusinessObjects.getOptionJsonFromObjectJson(
objectJson = storageLocation,
valueSelected = storageLocationJson[attrIdStorageLocation]
);
optionStorageLocation = DOM.createOption(optionStorageLocationJson);
console.log("optionStorageLocation: ", optionStorageLocation);
ddlStorageLocation.appendChild(optionStorageLocation);
});
let trBody = document.createElement("tr");
tdPlant.appendChild(ddlPlant);
trBody.appendChild(tdPlant);
tdStorageLocation.appendChild(ddlStorageLocation);
trBody.appendChild(tdStorageLocation);
tbody.appendChild(trBody);
tblStorageLocation.appendChild(tbody);
let parent = element.parentElement;
parent.innerHTML = '';
parent.appendChild(tblStorageLocation);
console.log("tblStorageLocation: ", tblStorageLocation);
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagPlant + ' select', (event, element) => { this.handleChangeStoragePlantDdl(event, element); });
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagStorageLocation + ' select', (event, element) => { this.handleChangeStorageLocationDdl(event, element); });
}
handleChangeStoragePlantDdl(event, ddlPlant) {
this.handleChangeTableCellDdl(event, ddlPlant);
let row = DOM.getRowFromElement(ddlPlant);
let ddlStorageLocation = row.querySelector('td.' + flagStorageLocation + ' select');
ddlStorageLocation.innerHTML = '';
ddlStorageLocation.appendChild(DOM.createOption(null));
let idPlant = DOM.getElementValueCurrent(ddlPlant);
let storageLocations = plants[idPlant][flagStorageLocations];
let optionJson, option;
storageLocations.forEach((storageLocation) => {
optionJson = BusinessObjects.getOptionJsonFromObjectJson(storageLocation);
option = DOM.createOption(optionJson);
ddlStorageLocation.appendChild(option);
});
this.handleChangeTableCellDdl(event, ddlStorageLocation);
}
handleChangeStorageLocationDdl(event, ddlStorageLocation) {
this.handleChangeTableCellDdl(event, ddlStorageLocation);
}
hookupSealingInputs() {
this.hookupIsSealedFields();
this.hookupDateUnsealedInputs();
}
hookupIsSealedFields(){
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagIsSealed + ' input', (event, element) => {
this.handleChangeElementCellTable(event, element);
let isSealed = DOM.getElementValueCurrent(element);
let row = DOM.getRowFromElement(element);
let inputDateUnsealed = row.querySelector('td.' + flagDateUnsealed + ' input');
if (isSealed) {
inputDateUnsealed.classList.add(flagCollapsed);
} else {
inputDateUnsealed.classList.remove(flagCollapsed);
}
});
}
hookupDateUnsealedInputs(){
this.hookupChangeHandlerTableCellsWhenNotCollapsed("change", idTableMain + ' td.' + flagDateUnsealed + ' input');
}
hookupExpirationDateInputs() {
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagDateExpiration + ' input');
}
hookupConsumationInputs() {
this.hookupIsConsumedFields();
this.hookupDateConsumedInputs();
}
hookupIsConsumedFields(){
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagIsConsumed + ' input', (event, element) => {
this.handleChangeElementCellTable(event, element);
let isConsumed = DOM.getElementValueCurrent(element);
let row = DOM.getRowFromElement(element);
let inputDateConsumed = row.querySelector('td.' + flagDateConsumed + ' input');
if (isConsumed) {
inputDateConsumed.classList.remove(flagCollapsed);
} else {
inputDateConsumed.classList.add(flagCollapsed);
}
});
}
hookupDateConsumedInputs(){
this.hookupChangeHandlerTableCellsWhenNotCollapsed("change", idTableMain + ' td.' + flagDateConsumed + ' input');
}
hookupActiveCheckboxes(){
this.hookupChangeHandlerTableCells(idTableMain + ' td.' + flagActive + ' input');
}
leave() {
super.leave();
}
getFiltersDefaults() {
filters = {};
filters.flagIsNotEmpty = true;
filters.flagActive = true;
return filters;
}
}