Initial commit

This commit is contained in:
user
2026-07-12 13:56:05 +04:00
commit 04bf3a4b58
850 changed files with 9057 additions and 0 deletions
@@ -0,0 +1,12 @@
USE [Database]
IF EXISTS(SELECT OBJECT_ID FROM [sys].[triggers] WHERE name = 'trg_drop_table')
DROP TRIGGER [trg_drop_table] ON DATABASE
GO
CREATE TRIGGER [trg_drop_table]
ON DATABASE FOR DROP_TABLE
AS
SET NOCOUNT ON;
ROLLBACK TRANSACTION;
GO
@@ -0,0 +1,20 @@
USE [Database]
IF OBJECT_ID('[Tables].[trg_insert_product_types]', 'TR') IS NOT NULL
DROP TRIGGER [Tables].[trg_insert_product_types];
GO
CREATE TRIGGER [Tables].[trg_insert_product_types] ON [Tables].[product_types] AFTER INSERT
AS
IF EXISTS(
SELECT *
FROM [inserted] AS [I]
JOIN [Tables].[product_types] AS [PT]
ON [PT].[id] = [I].[parent_id]
JOIN [Tables].[products] AS [p]
ON [p].[product_type_id] = [PT].[id]
)
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
GO
@@ -0,0 +1,34 @@
USE [Database]
IF OBJECT_ID('[Tables].[trg_insert_product_outflow_records]', 'TR') IS NOT NULL
DROP TRIGGER [Tables].[trg_insert_product_outflow_records];
GO
CREATE TRIGGER [Tables].[trg_insert_product_outflow_records] ON [Tables].[product_outflow_records] AFTER INSERT
AS
IF NOT EXISTS(
SELECT *
FROM [inserted] AS [i]
JOIN [Tables].[price_history_records] AS [phr]
ON [phr].[product_id] = [i].[product_id]
)
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
DECLARE @barcode_attribute_id AS INT;
SET @barcode_attribute_id = (
SELECT [id]
FROM [Tables].[attributes]
WHERE [name] = 'Barcode'
);
DECLARE @stocks AS INT;
SET @stocks = (
SELECT [Functions].[product_with_barcode_stock]([barcode])
FROM [inserted]
);
IF @stocks < 0
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
GO
@@ -0,0 +1,22 @@
USE [Database]
IF OBJECT_ID('[Tables].[trg_insert_product_values]', 'TR') IS NOT NULL
DROP TRIGGER [Tables].[trg_insert_product_values];
GO
CREATE TRIGGER [Tables].[trg_insert_product_values] ON [Tables].[product_values] AFTER INSERT
AS
IF EXISTS(
SELECT *
FROM (
SELECT [i].[value], COUNT(*) AS [count]
FROM [Tables].[product_values] AS [PV]
JOIN [inserted] AS [i]
ON [i].[id] = [PV].[product_id]
) AS [values]
WHERE [count] > 1
)
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
GO
@@ -0,0 +1,36 @@
USE [Database]
IF OBJECT_ID('[Tables].[trg_insert_product_outflow_records]', 'TR') IS NOT NULL
DROP TRIGGER [Tables].[trg_insert_product_outflow_records];
GO
CREATE TRIGGER [Tables].[trg_insert_product_outflow_records] ON [Tables].[product_outflow_records] AFTER INSERT
AS
IF NOT EXISTS(
SELECT *
FROM [inserted] AS [i]
JOIN [Tables].[product_values] AS [pv]
ON [pv].[id] = [i].[barcode_product_value_id]
JOIN [Tables].[price_history_records] AS [phr]
ON [phr].[product_id] = [pv].[product_id]
)
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
DECLARE @barcode_attribute_id AS INT;
SET @barcode_attribute_id = (
SELECT [id]
FROM [Tables].[attributes]
WHERE [name] = 'Barcode'
);
DECLARE @stocks AS INT;
SET @stocks = (
SELECT [Functions].[product_with_barcode_stock](@barcode_attribute_id, [barcode_product_value_id])
FROM [inserted]
);
IF @stocks < 0
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
GO
@@ -0,0 +1,25 @@
USE [Database]
IF OBJECT_ID('[Tables].[trg_insert_product_write_off_records]', 'TR') IS NOT NULL
DROP TRIGGER [Tables].[trg_insert_product_write_off_records];
GO
CREATE TRIGGER [Tables].[trg_insert_product_write_off_records] ON [Tables].[product_write_off_records] AFTER INSERT
AS
DECLARE @barcode_attribute_id AS INT;
SET @barcode_attribute_id = (
SELECT [id]
FROM [Tables].[attributes]
WHERE [name] = 'Barcode'
);
DECLARE @stocks AS INT;
SET @stocks = (
SELECT [Functions].[product_with_barcode_stock](@barcode_attribute_id, [barcode_product_value_id])
FROM [inserted]
);
IF @stocks < 0
BEGIN
ROLLBACK TRANSACTION;
RETURN;
END
GO