This commit is contained in:
seb
2026-09-26 23:06:05 +02:00
parent e491ecfa47
commit e7f92ebef8
41 changed files with 3632 additions and 1751 deletions

View File

@@ -7,6 +7,7 @@ function shape(row) {
return {
id: row.id,
manifestarticle_id: row.manifestarticle_id,
warehouse_id: row.warehouse_id ?? null,
sku: row.sku ?? null,
transaction_type: row.transaction_type,
amount: row.amount,
@@ -21,18 +22,18 @@ function shape(row) {
}
/**
* Lists ledger entries for a specific manifest article line, optionally filtered by transaction type.
* Lists ledger entries for a specific manifest article line, optionally filtered by transaction type and/or warehouse.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} manifestarticleId - The id of the manifest article line.
* @param {string|object} [optionsOrType] - Transaction type string or options object { transaction_type?: string, transactionType?: string }.
* @param {string|object} [optionsOrType] - Transaction type string or options object { transaction_type?: string, transactionType?: string, warehouse_id?: number, warehouseId?: number }.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<Array<{id: number, manifestarticle_id: number, sku: string|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>>}
* @returns {Promise<Array<{id: number, manifestarticle_id: number, warehouse_id: number|null, sku: string|null, transaction_type: string, amount: number, transaction_text: string, hash_version: number, prev_hash: string, created_at: string}>>}
* @throws {Error} If user not authorized, company not selected, or manifest article not found.
*
* @example
* const entries = await store.ledger.listByManifestarticleId(googleAuthId, 42, 'PAYMENT');
* // => [{ id, manifestarticle_id, sku, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at }]
* const entries = await store.ledger.listByManifestarticleId(googleAuthId, 42, 'DELIVERY');
* // => [{ id, manifestarticle_id, warehouse_id, sku, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at }]
*/
export default function listByManifestarticleId(provider) {
const access = resolveSelectedCompanyAccess(provider);
@@ -41,6 +42,7 @@ export default function listByManifestarticleId(provider) {
return async (googleAuthId, manifestarticleId, optionsOrType, tx) => {
let transactionType = null;
let warehouseId = null;
let explicitTx = tx;
if (typeof optionsOrType === 'string') {
@@ -54,6 +56,11 @@ export default function listByManifestarticleId(provider) {
if (typeof rawType === 'string') {
transactionType = rawType.trim() || null;
}
const rawWarehouse =
optionsOrType.warehouse_id ?? optionsOrType.warehouseId;
if (rawWarehouse != null) {
warehouseId = Number(rawWarehouse) || null;
}
}
}
@@ -78,6 +85,7 @@ export default function listByManifestarticleId(provider) {
manifestarticleId: id,
companyId,
transactionType: transactionType || null,
warehouseId: warehouseId || null,
});
return res.rows.map(shape);