This commit is contained in:
seb
2026-10-01 17:40:04 +02:00
parent 62c3e69ed4
commit 84e547660e
53 changed files with 4604 additions and 2059 deletions

View File

@@ -426,6 +426,9 @@ export class BetterSqlite3Provider extends BetterSqlite3Executor {
if (posterminalCols.length > 0 && !posterminalCols.includes('clientserial')) {
this.db.exec(`ALTER TABLE posterminal ADD COLUMN clientserial TEXT`);
}
if (posterminalCols.length > 0 && !posterminalCols.includes('maxknowntombstoneid')) {
this.db.exec(`ALTER TABLE posterminal ADD COLUMN maxknowntombstoneid INTEGER`);
}
const propertynameCols = this.db.pragma('table_info("propertyname")').map((c) => c.name);
if (propertynameCols.length > 0 && !propertynameCols.includes('exclusive')) {

View File

@@ -7,6 +7,29 @@ export const {
GET_CHILDREN_IDS, GET_LIST_IDS,
} = queries;
export const CREATE_TOMBSTONE = `
INSERT INTO articletombstone (company_id, article_id, sku, name, taxrate, net)
SELECT
a.company_id,
a.id AS article_id,
a.sku,
COALESCE(
(SELECT at.name FROM articletext at WHERE at.article_id = a.id AND at.language_id = co.default_language_id),
(SELECT at.name FROM articletext at WHERE at.article_id = a.id ORDER BY at.id ASC LIMIT 1)
) AS name,
COALESCE(
(SELECT t.rate FROM price pr INNER JOIN tax t ON t.id = pr.tax_id WHERE pr.article_id = a.id AND pr.customergroup_id = co.poscustomergroup_id AND pr.minmultiplier = 1),
(SELECT t.rate FROM price pr INNER JOIN tax t ON t.id = pr.tax_id WHERE pr.article_id = a.id ORDER BY pr.id ASC LIMIT 1)
) AS taxrate,
COALESCE(
(SELECT pr.net FROM price pr WHERE pr.article_id = a.id AND pr.customergroup_id = co.poscustomergroup_id AND pr.minmultiplier = 1),
(SELECT pr.net FROM price pr WHERE pr.article_id = a.id ORDER BY pr.id ASC LIMIT 1)
) AS net
FROM article a
INNER JOIN company co ON co.id = a.company_id
WHERE a.id = @articleId
`;
export const DELETE_PICS_BY_ARTICLE = `
DELETE FROM pic
WHERE id IN (SELECT pic_id FROM articlepic WHERE article_id = @articleId)

View File

@@ -2,4 +2,12 @@ import * as source from '../../mssql/queries/articlehistory.js';
import { translateQueries } from './translate.js';
const queries = translateQueries(source, 'articlehistory');
export const { INSERT, LIST_BY_ARTICLE_ID } = queries;
export const { INSERT, LIST_BY_ARTICLE_ID } = queries;
export const LIST_BY_ARTICLE_ID_LIMITED = `
SELECT id, companyuser_id AS companyuserId, date, text
FROM articlehistory
WHERE article_id = @articleId
ORDER BY date DESC, id DESC
LIMIT @limit
`;

View File

@@ -2,4 +2,8 @@ import * as source from '../../mssql/queries/articletext.js';
import { translateQueries } from './translate.js';
const queries = translateQueries(source, 'articletext');
export const { CREATE, UPDATE_BY_ARTICLE_AND_LANGUAGE } = queries;
export const {
CREATE,
UPDATE_BY_ARTICLE_AND_LANGUAGE,
LIST_SLUGS_BY_COMPANY_AND_LANGUAGE,
} = queries;

View File

@@ -0,0 +1,10 @@
import * as source from '../../mssql/queries/categoryattributevalue.js';
import { translateQueries } from './translate.js';
const queries = translateQueries(source, 'categoryattributevalue');
export const {
LIST_BY_CATEGORY_ID,
DELETE_BY_CATEGORY_ID,
INSERT_ROW,
GET_VALUE_DETAIL,
} = queries;

View File

@@ -0,0 +1,10 @@
import * as source from '../../mssql/queries/categoryproperty.js';
import { translateQueries } from './translate.js';
const queries = translateQueries(source, 'categoryproperty');
export const {
LIST_BY_CATEGORY_ID,
DELETE_BY_CATEGORY_ID,
DELETE_BY_CATEGORY_AND_PROPERTY_ID,
INSERT_ROW,
} = queries;

View File

@@ -3,7 +3,7 @@ import { translateQueries } from './translate.js';
const queries = translateQueries(source, 'manifestDoc');
export const {
CREATE_LINE, CREATE_MANIFEST, DELETE_LINES_BY_MANIFEST, DELETE_MANIFEST,
GET_MANIFEST_HEADER, GET_MANIFEST_LINES, LIST_MANIFESTS, ORDER_TYPE,
QUOTE_TYPE, UPDATE_MANIFEST,
CHECK_ARTICLE_IS_FATHER, CREATE_LINE, CREATE_MANIFEST, DELETE_LINES_BY_MANIFEST,
DELETE_MANIFEST, GET_MANIFEST_HEADER, GET_MANIFEST_LINES, LIST_MANIFESTS,
ORDER_TYPE, QUOTE_TYPE, UPDATE_MANIFEST,
} = queries;

View File

@@ -5,7 +5,7 @@ const queries = translateQueries(source, 'posterminal');
export const {
CREATE, DELETE_BY_COMPANY_AND_ID, GET_BY_ID, LIST_BY_COMPANY,
LIST_CATEGORY_IDS, POSTERMINAL_IDS_BY_COMPANY, SET_OFF, SET_OFF_ALL, UPDATE,
FIND_BY_PAIRINGPIN, PAIR,
FIND_BY_PAIRINGPIN, PAIR, SET_MAX_KNOWN_TOMBSTONE_ID,
FIND_BY_TOKEN, COUNT_PRODUCTS, COUNT_CATEGORIES, COUNT_CUSTOMERS,
COUNT_CUSTOMER_GROUPS, COUNT_COMPOSITE_PRODUCTS, MAX_ORDER_ID,
LIST_POS_PRODUCT_CATEGORIES, LIST_POS_CUSTOMER_GROUP_IDS, LIST_POS_PRODUCT_PRICES,

View File

@@ -495,6 +495,23 @@ CREATE TABLE IF NOT EXISTS articlehistory (
);
`;
export const INIT_ARTICLETOMBSTONE = `
CREATE TABLE IF NOT EXISTS articletombstone (
id INTEGER PRIMARY KEY,
company_id INTEGER NOT NULL,
article_id INTEGER,
sku TEXT COLLATE NOCASE,
name TEXT,
taxrate NUMERIC,
net REAL,
deleted_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
CHECK (article_id IS NOT NULL OR sku IS NOT NULL),
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS IX_articletombstone_company_deleted
ON articletombstone (company_id, deleted_at);
`;
export const INIT_ENTITYHISTORY = `
CREATE TABLE IF NOT EXISTS entityhistory (
id INTEGER PRIMARY KEY,
@@ -539,6 +556,7 @@ CREATE TABLE IF NOT EXISTS posterminal (
pairingpin TEXT NOT NULL,
paired_at TEXT,
clientserial TEXT,
maxknowntombstoneid INTEGER,
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX IF NOT EXISTS UQ_posterminal_token
@@ -684,6 +702,30 @@ CREATE TABLE IF NOT EXISTS articleattributevalue (
);
`;
export const INIT_CATEGORYPROPERTY = `
CREATE TABLE IF NOT EXISTS categoryproperty (
id INTEGER PRIMARY KEY,
category_id INTEGER NOT NULL,
property_id INTEGER NOT NULL,
value TEXT NOT NULL,
sort INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (category_id) REFERENCES category(id) ON DELETE CASCADE,
FOREIGN KEY (property_id) REFERENCES propertyname(id) ON DELETE CASCADE
);
`;
export const INIT_CATEGORYATTRIBUTEVALUE = `
CREATE TABLE IF NOT EXISTS categoryattributevalue (
id INTEGER PRIMARY KEY,
category_id INTEGER NOT NULL,
attributevalue_id INTEGER NOT NULL,
sort INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (category_id) REFERENCES category(id) ON DELETE CASCADE,
FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE,
UNIQUE (category_id, attributevalue_id)
);
`;
/** DDL scripts in dependency order for SQLite schema initialization. */
export const SCHEMA_SCRIPTS = [
INIT_META,
@@ -720,6 +762,8 @@ export const SCHEMA_SCRIPTS = [
INIT_ARTICLE_SUPPLIER,
INIT_ARTICLEPROPERTY,
INIT_ARTICLEATTRIBUTEVALUE,
INIT_CATEGORYPROPERTY,
INIT_CATEGORYATTRIBUTEVALUE,
INIT_MANIFEST,
INIT_MANIFESTARTICLE,
INIT_WAREHOUSE,
@@ -727,6 +771,7 @@ export const SCHEMA_SCRIPTS = [
INIT_NUMBERS,
INIT_COMPANYUSER,
INIT_ARTICLEHISTORY,
INIT_ARTICLETOMBSTONE,
INIT_ENTITYHISTORY,
INIT_SYNCPOS,
INIT_COMPANYSETTING,