u
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import * as mssqlQueries from '../../providers/mssql/queries/articlesupplier.js';
|
||||
import * as sqliteQueries from '../../providers/sqlite3/queries/articlesupplier.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from '../article/resolveArticleBySku.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
import {
|
||||
@@ -10,6 +8,7 @@ import {
|
||||
resolveCompanyDefaultTax,
|
||||
shapeArticleSupplier,
|
||||
} from './helpers.js';
|
||||
import { recordSupplierAddHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function create(provider) {
|
||||
@@ -18,7 +17,6 @@ export default function create(provider) {
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
|
||||
const queries = isSqlite ? sqliteQueries : mssqlQueries;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Assigns a supplier to an article, optionally creating a purchase price.
|
||||
@@ -150,21 +148,15 @@ export default function create(provider) {
|
||||
const supplierName =
|
||||
supplierRow?.supplierName ?? (entityId ? `Lieferant #${entityId}` : 'Lieferant');
|
||||
|
||||
const details = [];
|
||||
const actualSku = supplierRow?.sku ?? supplierSku;
|
||||
if (actualSku) {
|
||||
details.push(`Artikelnr: "${actualSku}"`);
|
||||
}
|
||||
const actualPrice = supplierRow?.priceNet ?? netPrice;
|
||||
if (actualPrice !== null && actualPrice !== undefined) {
|
||||
details.push(`EK: ${actualPrice}`);
|
||||
}
|
||||
const suffix = details.length ? ` (${details.join(', ')})` : '';
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordSupplierAddHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Lieferant "${supplierName}" hinzugefügt${suffix}`,
|
||||
supplierName,
|
||||
supplierSku: actualSku,
|
||||
netPrice: actualPrice,
|
||||
});
|
||||
|
||||
return shapeArticleSupplier(supplierRow);
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import * as mssqlQueries from '../../providers/mssql/queries/articlesupplier.js';
|
||||
import * as sqliteQueries from '../../providers/sqlite3/queries/articlesupplier.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from '../article/resolveArticleBySku.js';
|
||||
import { recordSupplierDeleteHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function del(provider) {
|
||||
const resolve = resolveArticleBySku(provider);
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
const queries = isSqlite ? sqliteQueries : mssqlQueries;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Deletes a supplier assignment and cleans up its associated purchase price.
|
||||
@@ -55,16 +53,11 @@ export default function del(provider) {
|
||||
const supplierName =
|
||||
existing.supplierName ?? (existing.entityId ? `Lieferant #${existing.entityId}` : 'Lieferant');
|
||||
|
||||
const details = [];
|
||||
if (existing.sku) {
|
||||
details.push(`Artikelnr: "${existing.sku}"`);
|
||||
}
|
||||
const suffix = details.length ? ` (${details.join(', ')})` : '';
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordSupplierDeleteHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Lieferant "${supplierName}" entfernt${suffix}`,
|
||||
supplierName,
|
||||
supplierSku: existing.sku,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import * as mssqlQueries from '../../providers/mssql/queries/articlesupplier.js';
|
||||
import * as sqliteQueries from '../../providers/sqlite3/queries/articlesupplier.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from '../article/resolveArticleBySku.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
import {
|
||||
@@ -9,6 +7,7 @@ import {
|
||||
resolveCompanyDefaultTax,
|
||||
shapeArticleSupplier,
|
||||
} from './helpers.js';
|
||||
import { recordSupplierUpdateHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function update(provider) {
|
||||
@@ -17,7 +16,6 @@ export default function update(provider) {
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
|
||||
const queries = isSqlite ? sqliteQueries : mssqlQueries;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Updates an existing supplier assignment and its associated purchase price.
|
||||
@@ -213,13 +211,12 @@ export default function update(provider) {
|
||||
}
|
||||
}
|
||||
|
||||
if (historyLines.length) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: historyLines.join('\n'),
|
||||
});
|
||||
}
|
||||
await recordSupplierUpdateHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
historyLines,
|
||||
supplierName,
|
||||
});
|
||||
|
||||
const loadRes = await runner.query(queries.GET_BY_ID_AND_ARTICLE_ID, {
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user