Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hugo Hörnquist
Stupan
Commits
7fa55fec
Commit
7fa55fec
authored
Apr 08, 2018
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed stock_diff_temp items from sql file
parent
693e7d6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
63 deletions
+5
-63
create-db.sql
create-db.sql
+5
-63
No files found.
create-db.sql
View file @
7fa55fec
...
...
@@ -102,27 +102,6 @@ CREATE TABLE stock_diff (
FOREIGN
KEY
(
product_id
)
REFERENCES
products
(
id
)
);
/*
* Table used in frontend
* Which is the reason for the redundant `diff` field.
*
* Note that the diff field is currently only updated in the frontent
*
* The expected_amount field should be nullable if null stock entries
* are to exist.
*
* NOTE This table is deprecated. Use diff_help instead
*/
CREATE
TABLE
stock_diff_temp
(
id
INTEGER
PRIMARY
KEY
NOT
NULL
,
product_id
INTEGER
NOT
NULL
,
expected_amount
INTEGER
NOT
NULL
,
actual_amount
INTEGER
,
diff
INTEGER
NOT
NULL
,
FOREIGN
KEY
(
product_id
)
REFERENCES
products
(
id
)
);
CREATE
TABLE
diff_help
(
id
INTEGER
PRIMARY
KEY
NOT
NULL
,
product_id
INTEGER
NOT
NULL
,
...
...
@@ -304,46 +283,6 @@ BEGIN
SELECT
id
,
price
FROM
current_products
WHERE
id
=
OLD
.
product_id
;
END
;
CREATE
TRIGGER
after_stock_diff_temp_delete
AFTER
DELETE
ON
stock_diff_temp
FOR
EACH
ROW
WHEN
(
SELECT
value
=
1
AND
NOT
(
OLD
.
actual_amount
IS
NULL
)
FROM
my_db_settings
WHERE
name
=
'stock_diff_temp_transfer'
)
BEGIN
UPDATE
stock
SET
active
=
OLD
.
actual_amount
WHERE
product_id
=
OLD
.
product_id
;
INSERT
INTO
stock_diff
(
product_id
,
expected
,
actual
)
SELECT
OLD
.
product_id
,
OLD
.
expected_amount
,
OLD
.
actual_amount
;
END
;
CREATE
TRIGGER
after_stock_diff_temp_delete_last
AFTER
DELETE
ON
stock_diff_temp
FOR
EACH
ROW
WHEN
(
SELECT
count
(
1
)
=
0
FROM
stock_diff_temp
)
BEGIN
INSERT
INTO
stock_diff_temp
(
product_id
,
expected_amount
,
diff
)
SELECT
p
.
id
,
s
.
active
,
-
s
.
active
FROM
products
p
INNER
JOIN
stock
s
ON
p
.
id
=
s
.
product_id
WHERE
p
.
sale_status
IN
(
0
,
1
);
END
;
/*
* This trigger is NOT loaded due to updates in the db
* not causing GUI updates.
* The exact same functionality is currently present in
* the GUI logic.
*/
/*
CREATE TRIGGER stock_diff_temp_diff
AFTER UPDATE OF expected_amount, actual_amount
ON stock_diff_temp
FOR EACH ROW
BEGIN
UPDATE stock_diff_temp
SET diff = NEW.actual_amount - NEW.expected_amount
WHERE id = NEW.id;
END;
*/
/*
* delete from the view to transfer,
* delete from the underlying table (diff_help) if
...
...
@@ -419,10 +358,13 @@ INSERT INTO money (name)
VALUES
(
"Cash Drawer"
),
(
"Vault"
);
INSERT
INTO
my_db_settings
(
name
,
value
)
VALUES
(
"stock_diff_temp_transfer"
,
1
),
(
"big_buy_transfer"
,
1
),
VALUES
(
"big_buy_transfer"
,
1
),
(
"acquisitions_temp_transfer"
,
1
);
-- This is mostly so that diff_help have something to insert
INSERT
INTO
products
(
name
)
VALUES
(
"Default Product"
);
-- diff_help gets it's data when the last record is deleted,
-- so insert *any* data and delete it.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment