Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[products_join_product_types]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[products_join_product_types];
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [Procedures].[products_join_product_types]
|
||||
AS
|
||||
SELECT [P].[id] AS [product_id], [P].[barcode],
|
||||
[P].[product_type_id] AS [product_type_id],
|
||||
[P].[name] AS [product_name],
|
||||
[PT].[name] AS [product_type_name]
|
||||
FROM [Tables].[products] AS [P]
|
||||
JOIN [Tables].[product_types] AS [PT]
|
||||
ON [PT].[id] = [P].[product_type_id]
|
||||
GO
|
||||
@@ -0,0 +1,14 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[rename_product]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[rename_product];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[rename_product]
|
||||
@product_id AS INT,
|
||||
@name AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[products]
|
||||
SET
|
||||
[name] = @name
|
||||
WHERE [id] = @product_id;
|
||||
GO
|
||||
@@ -0,0 +1,14 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[rename_product_type]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[rename_product_type];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[rename_product_type]
|
||||
@product_type_id AS INT,
|
||||
@name AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[product_types]
|
||||
SET
|
||||
[name] = @name
|
||||
WHERE [id] = @product_type_id;
|
||||
GO
|
||||
@@ -0,0 +1,27 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[specify_product_type]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[specify_product_type];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[specify_product_type]
|
||||
@parent_id INT = NULL,
|
||||
@name NVARCHAR(128),
|
||||
@inserted_product_type_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
SET NOCOUNT ON;
|
||||
|
||||
INSERT INTO [Tables].[product_types]([parent_id], [name])
|
||||
VALUES(DEFAULT, @name);
|
||||
SET @inserted_product_type_id = SCOPE_IDENTITY();
|
||||
|
||||
UPDATE [Tables].[products]
|
||||
SET [product_type_id] = @inserted_product_type_id
|
||||
WHERE [product_type_id] = @parent_id;
|
||||
|
||||
UPDATE [Tables].[product_types]
|
||||
SET [parent_id] = @parent_id
|
||||
WHERE [id] = @inserted_product_type_id
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
@@ -0,0 +1,18 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_barcode]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_barcode];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_barcode]
|
||||
@product_id INT,
|
||||
@barcode BIGINT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
SET NOCOUNT ON;
|
||||
|
||||
UPDATE [Tables].[products]
|
||||
SET [barcode] = @barcode
|
||||
WHERE [id] = @product_id
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
@@ -0,0 +1,22 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[get_next_barcode]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[get_next_barcode];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[get_next_barcode]
|
||||
@next_barcode AS BIGINT OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SET @next_barcode = (
|
||||
SELECT CAST([value] AS BIGINT) + 1
|
||||
FROM [Tables].[additional_variables]
|
||||
WHERE [id] = 1
|
||||
);
|
||||
|
||||
UPDATE [Tables].[additional_variables]
|
||||
SET [value] = CAST(@next_barcode AS NVARCHAR(13))
|
||||
WHERE [id] = 1;
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_or_update_barcode]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_or_update_barcode];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_or_update_barcode]
|
||||
@product_id AS INT,
|
||||
@barcode_attribute_id AS INT,
|
||||
@barcode AS BIGINT = NULL,
|
||||
@record_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
SET NOCOUNT ON;
|
||||
|
||||
IF @barcode IS NOT NULL AND EXISTS(
|
||||
SELECT *
|
||||
FROM [Tables].[product_values]
|
||||
WHERE [attribute_id] = @barcode_attribute_id
|
||||
AND CAST([value] AS BIGINT) = @barcode
|
||||
)
|
||||
BEGIN;
|
||||
IF @@TRANCOUNT > 0
|
||||
ROLLBACK TRANSACTION;
|
||||
THROW 53000, 'The barcode is not unique', 1;
|
||||
END;
|
||||
|
||||
CREATE TABLE [Tables].[#existing_hash_codes](
|
||||
[hash_code] NVARCHAR(13)
|
||||
);
|
||||
INSERT INTO [#existing_hash_codes]([hash_code])
|
||||
SELECT [value]
|
||||
FROM [Tables].[product_attributes] AS [pa]
|
||||
JOIN [Tables].[product_values] AS [pv]
|
||||
ON [pv].[product_id] = [pa].[product_id]
|
||||
AND [pv].[attribute_id] = [pa].[attribute_id]
|
||||
WHERE [pa].[attribute_id] = @barcode_attribute_id
|
||||
|
||||
-- begin creating barcode
|
||||
IF @barcode IS NULL
|
||||
EXECUTE [Procedures].[get_next_barcode] @next_barcode = @barcode OUTPUT;
|
||||
|
||||
WHILE EXISTS(
|
||||
SELECT *
|
||||
FROM [#existing_hash_codes]
|
||||
WHERE CAST([hash_code] AS BIGINT) = @barcode
|
||||
)
|
||||
OR EXISTS(
|
||||
SELECT *
|
||||
FROM [Tables].[product_values]
|
||||
WHERE [attribute_id] = @barcode_attribute_id
|
||||
AND CAST([value] AS BIGINT) = @barcode
|
||||
)
|
||||
BEGIN
|
||||
SET @barcode += 1;
|
||||
END
|
||||
-- end creating barcode
|
||||
|
||||
IF EXISTS(
|
||||
SELECT *
|
||||
FROM [Tables].[product_values]
|
||||
WHERE [attribute_id] = @barcode_attribute_id
|
||||
AND [product_id] = @product_id
|
||||
AND [value] IS NOT NULL
|
||||
)
|
||||
BEGIN
|
||||
UPDATE [Tables].[product_values]
|
||||
SET @record_id = [id],
|
||||
[value] = [Functions].[to_barcode_ean_13](@barcode)
|
||||
WHERE [product_id] = @product_id
|
||||
AND [attribute_id] = @barcode_attribute_id;
|
||||
END
|
||||
ELSE BEGIN
|
||||
INSERT INTO [Tables].[product_values]([product_id], [attribute_id], [value])
|
||||
VALUES(@product_id, @barcode_attribute_id, [Functions].[to_barcode_ean_13](@barcode));
|
||||
SET @record_id = SCOPE_IDENTITY();
|
||||
END
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
@@ -0,0 +1,16 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[product-properties]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[product-properties];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[product-properties]
|
||||
@product_id AS INT
|
||||
AS
|
||||
SELECT [A].[id], [A].[name], [PV].[value]
|
||||
FROM [Tables].[product_attributes] AS [PA]
|
||||
LEFT OUTER JOIN [Tables].[product_values] AS [PV]
|
||||
ON [PV].[product_id] = [PA].[product_id]
|
||||
AND [PV].[attribute_id] = [PA].[attribute_id]
|
||||
JOIN [Tables].[attributes] AS [A]
|
||||
ON [A].[id] = [PA].[attribute_id]
|
||||
WHERE [PA].[product_id] = @product_id;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[select_expired_products]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[select_expired_products];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[select_expired_products]
|
||||
@date_of_manufacture_attribute_id AS INT ,
|
||||
@expiration_date_attribute_id AS INT ,
|
||||
@actual_date AS DATE
|
||||
AS
|
||||
WITH [values] AS (
|
||||
SELECT [p].[id], [pa].[attribute_id], [pv].[value]
|
||||
FROM [Tables].[products] AS [p]
|
||||
JOIN [Tables].[product_attributes] AS [pa]
|
||||
ON [pa].[product_id] = [p].[id]
|
||||
JOIN [Tables].[product_values] AS [pv]
|
||||
ON [pv].[attribute_id] = [pa].[attribute_id]
|
||||
AND [pv].[product_id] = [pa].[product_id]
|
||||
WHERE [pa].[attribute_id] IN (@date_of_manufacture_attribute_id, @expiration_date_attribute_id)
|
||||
)
|
||||
SELECT [date_of_manufacture_attributes].[id]
|
||||
FROM [values] AS date_of_manufacture_attributes
|
||||
JOIN [values] AS expiration_date_attributes
|
||||
ON [expiration_date_attributes].[id] = [date_of_manufacture_attributes].[id]
|
||||
AND [expiration_date_attributes].[attribute_id] = @expiration_date_attribute_id
|
||||
WHERE [date_of_manufacture_attributes].[attribute_id] = @date_of_manufacture_attribute_id
|
||||
AND DATEADD(
|
||||
DAY, CAST([expiration_date_attributes].[value] AS INT),
|
||||
CAST([date_of_manufacture_attributes].[value] AS DATE)
|
||||
) < @actual_date;
|
||||
GO
|
||||
@@ -0,0 +1,37 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[tree_positions]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[tree_positions];
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [Procedures].[tree_positions]
|
||||
@product_type_id INT
|
||||
AS
|
||||
IF OBJECT_ID('[tempdb].[dbo].[#product_types_row_number]') IS NOT NULL
|
||||
DROP TABLE [dbo].[#product_types_row_number];
|
||||
CREATE TABLE [#product_types_row_number]
|
||||
(
|
||||
[id] INT NOT NULL,
|
||||
[parent_id] INT,
|
||||
[row_number] INT NOT NULL
|
||||
);
|
||||
INSERT INTO [#product_types_row_number]
|
||||
SELECT [id], [parent_id], ROW_NUMBER() OVER (PARTITION BY [parent_id] ORDER BY [parent_id], [id] ASC) - 1
|
||||
FROM [Tables].[product_types];
|
||||
|
||||
WITH [result] AS (
|
||||
SELECT
|
||||
[id], [parent_id], [row_number]
|
||||
FROM [#product_types_row_number]
|
||||
WHERE [id] = @product_type_id
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT [PT].[id], [PT].[parent_id], [PT].[row_number]
|
||||
FROM [result] AS [R]
|
||||
JOIN [#product_types_row_number] AS [PT]
|
||||
ON [PT].[id] = [R].[parent_id]
|
||||
)
|
||||
SELECT [id], [parent_id], [row_number]
|
||||
FROM [result]
|
||||
ORDER BY [id];
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product]
|
||||
@name AS NVARCHAR(128),
|
||||
@product_type_id AS INT,
|
||||
@barcode AS BIGINT,
|
||||
@inserted_product_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[products]([barcode], [name], [product_type_id])
|
||||
VALUES(@barcode, @name, @product_type_id);
|
||||
SET @inserted_product_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_attribute]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_attribute];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_attribute]
|
||||
@product_id AS INT,
|
||||
@attribute_id AS INT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[product_attributes]([product_id], [attribute_id])
|
||||
VALUES (@product_id, @attribute_id);
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_type]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_type];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_type]
|
||||
@parent_id AS INT = NULL,
|
||||
@name AS NVARCHAR(128),
|
||||
@inserted_product_type_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRY
|
||||
INSERT INTO [Tables].[product_types]([parent_id], [name])
|
||||
VALUES(@parent_id, @name);
|
||||
SET @inserted_product_type_id = SCOPE_IDENTITY();
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
DECLARE @message NVARCHAR(128);
|
||||
SET @message =
|
||||
'Cannot create [a] subgroup. Cause: the group '
|
||||
+ '(name: "'+ (SELECT [name] FROM [Tables].[product_types] WHERE [id] = @parent_id) +'"; [id]:'+ LTRIM(STR(@parent_id)) +')'
|
||||
+ ' is referenced by [a] product object.';
|
||||
PRINT 'Actual error number: ' + CAST(ERROR_NUMBER() AS NVARCHAR(10));
|
||||
PRINT 'Actual line number: ' + CAST(ERROR_LINE() AS NVARCHAR(10));
|
||||
THROW 51000, @message, 1;
|
||||
END CATCH
|
||||
GO
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_value]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_value];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_value]
|
||||
@product_id AS INT,
|
||||
@attribute_id AS INT,
|
||||
@value AS NVARCHAR(128)
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[product_values]([product_id], [attribute_id], [value])
|
||||
VALUES (@product_id, @attribute_id, @value);
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product]
|
||||
@name AS NVARCHAR(128),
|
||||
@product_type_id AS INT,
|
||||
@barcode_attribute_id AS INT,
|
||||
@inserted_product_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[products]([barcode], [name], [product_type_id])
|
||||
VALUES(@name, @product_type_id);
|
||||
SET @inserted_product_id = SCOPE_IDENTITY();
|
||||
|
||||
INSERT INTO [Tables].[product_attributes]([product_id], [attribute_id])
|
||||
VALUES (@inserted_product_id, @barcode_attribute_id);
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_type]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_type];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_type]
|
||||
@product_type_id AS INT
|
||||
AS
|
||||
DECLARE @newParentId INT;
|
||||
SET @newParentId = (
|
||||
SELECT [parent_id]
|
||||
FROM [Tables].[product_types]
|
||||
WHERE [id] = @product_type_id
|
||||
)
|
||||
BEGIN TRANSACTION;
|
||||
UPDATE [Tables].[product_types]
|
||||
SET [parent_id] = @newParentId
|
||||
WHERE [parent_id] = @product_type_id
|
||||
|
||||
DELETE FROM [Tables].[product_types]
|
||||
WHERE [id] = @product_type_id;
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product]
|
||||
@product_id AS INT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
DELETE FROM [Tables].[product_values]
|
||||
WHERE [product_id] = @product_id;
|
||||
DELETE FROM [Tables].[product_attributes]
|
||||
WHERE [product_id] = @product_id;
|
||||
DELETE FROM [Tables].[products]
|
||||
WHERE [id] = @product_id;
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_attribute]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_attribute];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_attribute]
|
||||
@name AS NVARCHAR(128),
|
||||
@inserted_attribute_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[attributes]([name])
|
||||
VALUES (@name);
|
||||
SET @inserted_attribute_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_price_history_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_price_history_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_price_history_record]
|
||||
@product_id AS INT,
|
||||
@datetime AS DATETIME,
|
||||
@price AS MONEY,
|
||||
@inserted_price_history_record_id INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[price_history_records]([product_id], [datetime], [price])
|
||||
VALUES (@product_id, @datetime, @price);
|
||||
SET @inserted_price_history_record_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_inflow_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_inflow_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_inflow_record]
|
||||
@barcode_product_value_id AS INT,
|
||||
@barcode_product_attribute_id AS INT,
|
||||
@supplier_id AS INT,
|
||||
@count AS INT,
|
||||
@full_price AS INT,
|
||||
@datetime AS DATETIME,
|
||||
@inserted_product_inflow_record_id INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[product_inflow_records]([barcode_product_value_id], [supplier_id], [count], [full_price], [datetime])
|
||||
VALUES (@barcode_product_value_id, @supplier_id, @count, @full_price, @datetime);
|
||||
SET @inserted_product_inflow_record_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_outflow_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_outflow_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_outflow_record]
|
||||
@barcode_product_outflow_record_id AS INT,
|
||||
@count AS INT,
|
||||
@datetime AS DATETIME,
|
||||
@inserted_product_outflow_records INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[product_outflow_records]([barcode_product_value_id], [count], [datetime])
|
||||
VALUES (@barcode_product_outflow_record_id, @count, @datetime);
|
||||
SET @inserted_product_outflow_records = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_value]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_value];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_value]
|
||||
@product_id AS INT,
|
||||
@attribute_id AS INT,
|
||||
@value AS NVARCHAR(128),
|
||||
@inserted_product_value_id INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[product_values]([product_id], [attribute_id], [value])
|
||||
VALUES (@product_id, @attribute_id, @value);
|
||||
SET @inserted_product_value_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_product_write_off_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_product_write_off_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_product_write_off_record]
|
||||
@barcode_product_value_id AS INT,
|
||||
@reason_id AS INT,
|
||||
@count AS INT,
|
||||
@datetime AS DATETIME,
|
||||
@inserted_product_write_off_record_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[product_write_off_records]([barcode_product_value_id], [reason_id], [count], [datetime])
|
||||
VALUES (@barcode_product_value_id, @reason_id, @count, @datetime);
|
||||
SET @inserted_product_write_off_record_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_supplier]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_supplier];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_supplier]
|
||||
@name AS NVARCHAR(128),
|
||||
@address AS NVARCHAR(128),
|
||||
@telephone_number AS NVARCHAR(128),
|
||||
@inserted_supplier_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[suppliers]([name], [address], [telephone_number])
|
||||
VALUES (@name, @address, @telephone_number);
|
||||
SET @inserted_supplier_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[insert_write_off_reason]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[insert_write_off_reason];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[insert_write_off_reason]
|
||||
@name AS NVARCHAR(128),
|
||||
@inserted_write_off_reason_id AS INT = NULL OUTPUT
|
||||
AS
|
||||
BEGIN TRANSACTION;
|
||||
INSERT INTO [Tables].[write_off_reasons]([name])
|
||||
VALUES (@name);
|
||||
SET @inserted_write_off_reason_id = SCOPE_IDENTITY();
|
||||
COMMIT TRANSACTION;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_inflow_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_inflow_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_inflow_record]
|
||||
@product_inflow_record_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[product_inflow_records]
|
||||
WHERE [id] = @product_inflow_record_id;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_type]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_type];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_type]
|
||||
@product_type_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[product_types]
|
||||
WHERE [id] = @product_type_id;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_write_off_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_write_off_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_write_off_record]
|
||||
@product_write_off_record_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[product_write_off_records]
|
||||
WHERE [id] = @product_write_off_record_id;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_attribute]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_attribute];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_attribute]
|
||||
@attribute_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[attributes]
|
||||
WHERE [id] = @attribute_id;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_price_history_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_price_history_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_price_history_record]
|
||||
@price_history_record_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[price_history_records]
|
||||
WHERE [id] = @price_history_record_id;
|
||||
GO
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_attribute]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_attribute];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_attribute]
|
||||
@product_id AS INT,
|
||||
@product_attribute_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[product_attributes]
|
||||
WHERE [product_id] = @product_attribute_id
|
||||
AND [attribute_id] = @product_attribute_id
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_outflow_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_outflow_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_outflow_record]
|
||||
@product_outflow_record_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[product_outflow_records]
|
||||
WHERE [id] = @product_outflow_record_id;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_product_value]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_product_value];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_product_value]
|
||||
@product_value_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[product_values]
|
||||
WHERE [id] = @product_value_id;
|
||||
GO
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[delete_supplier]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[delete_supplier];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[delete_supplier]
|
||||
@supplier_id AS INT
|
||||
AS
|
||||
DELETE FROM [Tables].[suppliers]
|
||||
WHERE [id] = @supplier_id;
|
||||
GO
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_attribute]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_attribute];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_attribute]
|
||||
@attribute_id AS INT,
|
||||
@name AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[attributes]
|
||||
SET [name] = @name
|
||||
WHERE [id] = @attribute_id;
|
||||
GO
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_price_history_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_price_history_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_price_history_record]
|
||||
@price_history_record_id AS INT,
|
||||
@product_id AS INT,
|
||||
@datetime AS DATETIME,
|
||||
@price AS MONEY
|
||||
AS
|
||||
UPDATE [Tables].[price_history_records]
|
||||
SET
|
||||
[product_id] = @product_id,
|
||||
[datetime] = @datetime,
|
||||
[price] = @price
|
||||
WHERE [id] = @price_history_record_id;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_product]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_product];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_product]
|
||||
@product_id AS INT,
|
||||
@name AS NVARCHAR(128),
|
||||
@product_type_id AS INT,
|
||||
@barcode_attribute_id AS INT
|
||||
AS
|
||||
UPDATE [Tables].[products]
|
||||
SET
|
||||
[name] = @name,
|
||||
[product_type_id] = @product_type_id
|
||||
WHERE [id] = @product_id;
|
||||
GO
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_product_inflow_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_product_inflow_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_product_inflow_record]
|
||||
@product_inflow_record_id AS INT,
|
||||
@barcode_product_value_id AS INT,
|
||||
@supplier_id AS INT,
|
||||
@count AS INT,
|
||||
@full_price AS INT,
|
||||
@datetime AS DATETIME
|
||||
AS
|
||||
UPDATE [Tables].[product_inflow_records]
|
||||
SET
|
||||
[barcode_product_value_id] = @barcode_product_value_id,
|
||||
[supplier_id] = @supplier_id,
|
||||
[count] = @count,
|
||||
[full_price] = @full_price,
|
||||
[datetime] = @datetime
|
||||
WHERE [id] = @product_inflow_record_id;
|
||||
GO
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_product_outflow_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_product_outflow_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_product_outflow_record]
|
||||
@product_outflow_record_id AS INT,
|
||||
@barcode_product_value_record_id AS INT,
|
||||
@count AS INT,
|
||||
@datetime AS INT,
|
||||
@inserted_product_outflow_records AS INT = NULL OUTPUT
|
||||
AS
|
||||
UPDATE [Tables].[product_outflow_records]
|
||||
SET
|
||||
[barcode_product_value_id] = @barcode_product_value_record_id,
|
||||
[count] = @count,
|
||||
[datetime] = @datetime
|
||||
WHERE [id] = @product_outflow_record_id;
|
||||
GO
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_product_type]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_product_type];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_product_type]
|
||||
@product_type_id AS INT,
|
||||
@parent_id AS INT = NULL,
|
||||
@name AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[product_types]
|
||||
SET
|
||||
[parent_id] = @parent_id,
|
||||
[name] = @name
|
||||
WHERE [id] = @product_type_id;
|
||||
GO
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_product_value]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_product_value];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_product_value]
|
||||
@product_value_id AS INT,
|
||||
@product_id AS INT,
|
||||
@attribute_id AS INT,
|
||||
@value AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[product_values]
|
||||
SET
|
||||
[product_id] = @product_id,
|
||||
[attribute_id] = @attribute_id,
|
||||
[value] = @value
|
||||
WHERE [id] = @product_value_id;
|
||||
GO
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_product_write_off_record]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_product_write_off_record];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_product_write_off_record]
|
||||
@product_write_off_record_id AS INT,
|
||||
@barcode_product_value_id AS INT,
|
||||
@reason_id AS INT,
|
||||
@count AS INT,
|
||||
@datetime AS DATETIME
|
||||
AS
|
||||
UPDATE [Tables].[product_write_off_records]
|
||||
SET
|
||||
[barcode_product_value_id] = @barcode_product_value_id,
|
||||
[reason_id] = @reason_id,
|
||||
[count] = @count,
|
||||
[datetime] = @datetime
|
||||
WHERE [id] = @product_write_off_record_id;
|
||||
GO
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_supplier]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_supplier];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_supplier]
|
||||
@supplier_id AS INT,
|
||||
@name AS NVARCHAR(128),
|
||||
@address AS NVARCHAR(128),
|
||||
@telephone_number AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[suppliers]
|
||||
SET
|
||||
[name] = @name,
|
||||
[address] = @address,
|
||||
[telephone_number] = @telephone_number
|
||||
WHERE [id] = @supplier_id;
|
||||
GO
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Procedures].[update_write_off_reason]', 'P') IS NOT NULL
|
||||
DROP PROCEDURE [Procedures].[update_write_off_reason];
|
||||
GO
|
||||
CREATE PROCEDURE [Procedures].[update_write_off_reason]
|
||||
@write_off_reason_id AS INT,
|
||||
@name AS NVARCHAR(128)
|
||||
AS
|
||||
UPDATE [Tables].[write_off_reasons]
|
||||
SET [name] = @name
|
||||
WHERE [id] = @write_off_reason_id;
|
||||
GO
|
||||
Reference in New Issue
Block a user