feat(web): documentos de ventas y compras con tipo Artículo / Servicio (columnas de línea, validación, guardado y copiado)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
68d2cfe6d0
commit
2e74bccd65
11 files changed
+260
-25
No files matched your search
@@ -4,7 +4,7 @@ import type { VhLookup } from '../../shared/value-help/value-help.types';
|
||||
import type { DocRecord, LinesSpec } from './document-model';
|
||||
import { INDICATOR_LOOKUP, PROJECT_LOOKUP } from './dimension-lookups';
|
||||
import { SERIES_SUBTYPE } from './document-objects';
|
||||
import { ANALYTIC_COLUMNS, DOCUMENT_LINE_COLUMNS, lineColumnsFor, lineFieldsOf, newDocumentLine, recalcLine, uomEntryOf } from './line-columns';
|
||||
import { ANALYTIC_COLUMNS, DOCUMENT_LINE_COLUMNS, lineColumnsFor, lineFieldsOf, newDocumentLine, newServiceLine, recalcLine, serviceLineColumns, uomEntryOf } from './line-columns';
|
||||
|
||||
/** Valores calculados o del socio que una fila de solo lectura puede mostrar. */
|
||||
export type ComputedSource = 'docNum' | 'partnerName' | 'partnerTaxId' | 'subtotal' | 'tax' | 'total';
|
||||
@@ -86,14 +86,34 @@ export interface DocumentLayout {
|
||||
/** Ajustes a la cabecera antes de crear. */
|
||||
beforeCreate?: (header: DocRecord) => DocRecord;
|
||||
requiredLine: readonly { key: string; label: string }[];
|
||||
/**
|
||||
* Cómo cambia el documento cuando es de tipo **Servicio** (`DocType = dDocument_Service`): otras columnas de línea
|
||||
* y otros campos que se guardan. Solo lo tienen los documentos de ventas y compras, que además llevan en la
|
||||
* cabecera la lista «Tipo» (`FIELDS.docType`).
|
||||
*/
|
||||
service?: { columns: readonly GridColumn[]; lines: LinesSpec; newLine: () => GridLine };
|
||||
}
|
||||
|
||||
/** Un documento de servicio (no de artículos): `DocType` de SAP. */
|
||||
export const SERVICE_DOC_TYPE = 'dDocument_Service';
|
||||
export const ITEMS_DOC_TYPE = 'dDocument_Items';
|
||||
|
||||
export const today = (): string => new Date().toISOString().slice(0, 10);
|
||||
|
||||
// --- catálogo de campos ---------------------------------------------------------------------
|
||||
|
||||
/** Catálogo de campos: cada pantalla elige cuáles lleva. */
|
||||
export const FIELDS = {
|
||||
/** Tipo del documento: de artículos o de servicio (las líneas cambian). */
|
||||
docType: {
|
||||
type: 'select',
|
||||
key: 'DocType',
|
||||
label: 'Tipo',
|
||||
options: [
|
||||
{ value: ITEMS_DOC_TYPE, label: 'Artículo' },
|
||||
{ value: SERVICE_DOC_TYPE, label: 'Servicio' },
|
||||
],
|
||||
},
|
||||
docNum: { type: 'computed', label: 'Número', source: 'docNum' },
|
||||
/** Número del documento con su serie. */
|
||||
docNumber: { type: 'series', key: 'Series', label: 'Número' },
|
||||
@@ -224,6 +244,7 @@ export function marketingLayout(opts: {
|
||||
lines: { key: 'DocumentLines', fields: [...lineFieldsOf(columns), 'UoMEntry'], base: true },
|
||||
header: opts.header ?? {
|
||||
left: [
|
||||
FIELDS.docType,
|
||||
{ type: 'partner', key: 'CardCode', label: opts.partnerLabel, required: true, missing: `el ${opts.partnerLabel.toLowerCase()}` },
|
||||
{ type: 'computed', label: 'Nombre', source: 'partnerName' },
|
||||
{ type: 'computed', label: 'RUT', source: 'partnerTaxId' },
|
||||
@@ -245,9 +266,14 @@ export function marketingLayout(opts: {
|
||||
],
|
||||
},
|
||||
columns,
|
||||
newHeader: () => ({ DocDate: today(), DocDueDate: today(), DiscountPercent: 0 }),
|
||||
newHeader: () => ({ DocType: ITEMS_DOC_TYPE, DocDate: today(), DocDueDate: today(), DiscountPercent: 0 }),
|
||||
newLine: newDocumentLine,
|
||||
recalc: recalcLine,
|
||||
service: {
|
||||
columns: serviceLineColumns(opts.taxResource),
|
||||
lines: { key: 'DocumentLines', fields: lineFieldsOf(serviceLineColumns(opts.taxResource)), base: true, service: true },
|
||||
newLine: newServiceLine,
|
||||
},
|
||||
seriesSubType: SERIES_SUBTYPE[String(opts.fixed?.['DocumentSubType'] ?? 'bod_None')] ?? '--',
|
||||
...(opts.fixed ? { beforeCreate: (h: DocRecord) => ({ ...h, ...opts.fixed }) } : {}),
|
||||
requiredLine: [],
|
||||
|
||||
Reference in new issue
Block a user