66 lines
2.5 KiB
TypeScript
66 lines
2.5 KiB
TypeScript
import {
|
|
type DocumentLayout,
|
|
FIELDS,
|
|
blankLine,
|
|
commentsOnly,
|
|
descriptionColumn,
|
|
itemColumn,
|
|
priceColumn,
|
|
quantityColumn,
|
|
today,
|
|
warehouseColumn,
|
|
} from '../document-layouts';
|
|
import type { GridColumn } from '../../../shared/grid/grid.types';
|
|
import { ANALYTIC_COLUMNS, lineFieldsOf } from '../line-columns';
|
|
|
|
/** Entradas y salidas de mercancía: artículo, cantidad, almacén y precio (opcional: si falta, SAP usa el costo). */
|
|
const goodsColumns: readonly GridColumn[] = [itemColumn, descriptionColumn, quantityColumn, { ...warehouseColumn, required: true }, priceColumn, ...ANALYTIC_COLUMNS];
|
|
export const goodsLayout: DocumentLayout = {
|
|
lines: { key: 'DocumentLines', fields: [...lineFieldsOf(goodsColumns), 'UoMEntry'], base: false },
|
|
header: { left: [FIELDS.docDate, FIELDS.indicator, FIELDS.project], right: [FIELDS.docNumber] },
|
|
footer: commentsOnly,
|
|
columns: goodsColumns,
|
|
newHeader: () => ({ DocDate: today() }),
|
|
newLine: () => ({ ...blankLine(), Price: null }),
|
|
immutable: true,
|
|
requiredLine: [{ key: 'WarehouseCode', label: 'el almacén' }],
|
|
};
|
|
|
|
/** Transferencias de stock y solicitudes de traslado: almacén origen y destino en la cabecera y en cada línea. */
|
|
const transfer = (immutable: boolean): DocumentLayout => {
|
|
const columns: readonly GridColumn[] = [
|
|
itemColumn,
|
|
descriptionColumn,
|
|
quantityColumn,
|
|
{
|
|
...warehouseColumn,
|
|
key: 'FromWarehouseCode',
|
|
title: 'Almacén origen',
|
|
required: true,
|
|
lookup: { ...warehouseColumn.lookup!, apply: (wh, line) => ({ ...line, FromWarehouseCode: wh['WarehouseCode'] }) },
|
|
},
|
|
{ ...warehouseColumn, title: 'Almacén destino', required: true },
|
|
...ANALYTIC_COLUMNS,
|
|
];
|
|
return {
|
|
lines: { key: 'StockTransferLines', fields: [...lineFieldsOf(columns), 'UoMEntry'], base: false },
|
|
header: { left: [FIELDS.fromWarehouse, FIELDS.toWarehouse, FIELDS.indicator, FIELDS.project], right: [FIELDS.docNumber, FIELDS.docDate] },
|
|
footer: commentsOnly,
|
|
columns,
|
|
newHeader: () => ({ DocDate: today() }),
|
|
newLine: (header) => ({
|
|
...blankLine(),
|
|
FromWarehouseCode: header['FromWarehouse'] ?? '',
|
|
WarehouseCode: header['ToWarehouse'] ?? '',
|
|
}),
|
|
immutable,
|
|
requiredLine: [
|
|
{ key: 'FromWarehouseCode', label: 'el almacén origen' },
|
|
{ key: 'WarehouseCode', label: 'el almacén destino' },
|
|
],
|
|
};
|
|
};
|
|
|
|
export const transferLayout: DocumentLayout = transfer(true);
|
|
export const transferRequestLayout: DocumentLayout = transfer(false);
|