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

@@ -1,5 +1,11 @@
import { CREATE_LINE as MSSQL_CREATE_LINE } from '../providers/mssql/queries/manifestDoc.js';
import { CREATE_LINE as SQLITE_CREATE_LINE } from '../providers/sqlite3/queries/manifestDoc.js';
import {
CHECK_ARTICLE_IS_FATHER as MSSQL_CHECK_ARTICLE_IS_FATHER,
CREATE_LINE as MSSQL_CREATE_LINE,
} from '../providers/mssql/queries/manifestDoc.js';
import {
CHECK_ARTICLE_IS_FATHER as SQLITE_CHECK_ARTICLE_IS_FATHER,
CREATE_LINE as SQLITE_CREATE_LINE,
} from '../providers/sqlite3/queries/manifestDoc.js';
import makeRunner from './runner.js';
/**
@@ -24,7 +30,7 @@ export function normalizeLines(lines) {
}
const pu =
entry?.pu === undefined || entry?.pu === null ? 1 : entry.pu;
entry?.pu === undefined || entry?.pu === null ? null : entry.pu;
const amount = entry?.amount;
const net = entry?.net;
const rebate =
@@ -36,7 +42,7 @@ export function normalizeLines(lines) {
: String(entry.comment);
if (
typeof pu !== 'number' || !Number.isFinite(pu) || pu <= 0 ||
(pu !== null && (typeof pu !== 'number' || !Number.isFinite(pu) || pu <= 0)) ||
typeof amount !== 'number' || !Number.isFinite(amount) ||
typeof net !== 'number' || !Number.isFinite(net) ||
typeof rebate !== 'number' || !Number.isFinite(rebate) ||
@@ -116,8 +122,32 @@ export async function insertLines(
const { manifestId, lines, ensureTax } = params;
const isSqlite = runner?.dialect === 'sqlite3';
const createLineSql = isSqlite ? SQLITE_CREATE_LINE : MSSQL_CREATE_LINE;
const checkFatherSql = isSqlite ? SQLITE_CHECK_ARTICLE_IS_FATHER : MSSQL_CHECK_ARTICLE_IS_FATHER;
for (const line of lines) {
let resolvedName = line.name;
let resolvedPu = line.pu;
if (line.sku) {
const fatherCheck = await runner.query(checkFatherSql, {
manifestId,
sku: line.sku,
});
const art = fatherCheck.rows[0];
if (art?.isFather) {
throw new Error(`A father article cannot be booked on documents (${line.sku})`);
}
if (!resolvedName && art?.articleName) {
resolvedName = art.articleName;
}
if (resolvedPu == null && art?.pu != null) {
resolvedPu = art.pu;
}
}
resolvedName = resolvedName || line.sku || null;
resolvedPu = resolvedPu ?? 1;
if (ensureTax) {
await ensureTax(line.taxrate, runner);
}
@@ -125,8 +155,8 @@ export async function insertLines(
await runner.query(createLineSql, {
manifestId,
sku: line.sku ?? null,
name: line.name ?? null,
pu: line.pu ?? 1,
name: resolvedName,
pu: resolvedPu,
amount: line.amount,
net: line.net,
comment: line.comment,