This commit is contained in:
seb
2026-10-23 20:31:34 +02:00
parent 57347bdef9
commit b9bd0380cb
7 changed files with 533 additions and 78 deletions

View File

@@ -21,6 +21,10 @@ import customergroupAutomat from '../../automats/customergroupAutomat';
import supplierAutomat from '../../automats/supplierAutomat';
import orderAutomat from '../../automats/orderAutomat';
import companyAutomat, { selectCompanyTaxrate } from '../../automats/companyAutomat';
import warehouseAutomat from '../../automats/warehouseAutomat';
import sseAutomat from '../../automats/sseAutomat';
import OrderLedgerPanel from './OrderLedgerPanel';
import { fetchOrderLedgerEntries } from '../../utils/orderLedger';
import { netFromGross, grossFromNet, getArticleGross } from '../../utils/price';
import { resolveSalesPrice } from '../../utils/articleDetail';
import {
@@ -102,6 +106,7 @@ class ManifestForm extends PureComponent {
shipments: initialEdit?.shipments || [],
payments: initialEdit?.payments || [],
shippings: initialEdit?.shippings || [],
ledgerEntries: [],
orderTotal: initialEdit?.orderTotal ?? null,
paidTotal: initialEdit?.paidTotal ?? null,
paid: Boolean(initialEdit?.paid),
@@ -217,8 +222,20 @@ class ManifestForm extends PureComponent {
}
});
if (warehouseAutomat.state.status === 'idle') {
void warehouseAutomat.actions.load();
}
if (this.props.mode === 'edit') {
void this.loadEdit();
if (this.props.kind === 'order') {
this.unsubSseLedger = sseAutomat?.actions?.on?.('ledger', () => {
void this.reloadLedger();
});
this.unsubSseStock = sseAutomat?.actions?.on?.('stock', () => {
void this.reloadLedger();
});
}
} else {
void this.loadPartiesOnly();
void ensureDocumentNumber(this.props.kind).catch(() => {});
@@ -359,12 +376,28 @@ class ManifestForm extends PureComponent {
this.unsubParties?.();
this.unsubGroups?.();
this.unsubCompany?.();
this.unsubSseLedger?.();
this.unsubSseStock?.();
if (this._parseAbortController) {
this._parseAbortController.abort();
this._parseAbortController = null;
}
}
async reloadLedger() {
if (this.props.kind !== 'order' || this.props.mode !== 'edit' || !this.props.docId) return;
try {
const ledgerEntries = await fetchOrderLedgerEntries(this.props.docId, {
shipments: this.state.shipments,
lines: this.state.lines,
});
if (this._cancelled) return;
this.setState({ ledgerEntries });
} catch (err) {
console.warn('[ManifestForm] Failed to reload ledger entries:', err);
}
}
async loadPartiesOnly() {
if (this.state.parties.length === 0) {
this.setState({ status: 'loadingParties', error: null, partiesLoading: true });
@@ -464,6 +497,18 @@ class ManifestForm extends PureComponent {
}
}
let ledgerEntries = [];
if (kind === 'order') {
try {
ledgerEntries = await fetchOrderLedgerEntries(docId, {
shipments,
lines: doc.lines,
});
} catch (lErr) {
console.warn('[ManifestForm] Failed to load ledger entries:', lErr);
}
}
const loadedDoc = {
date: dateInputValue(doc.date),
partyId: doc[cfg.partyField],
@@ -492,6 +537,7 @@ class ManifestForm extends PureComponent {
parties,
partiesLoading: false,
...loadedDoc,
ledgerEntries,
isDirty: false,
dirtyFields: null,
dirtyLineKeys: [],
@@ -1409,6 +1455,9 @@ class ManifestForm extends PureComponent {
navigate={this.props.navigate}
/>
) : null}
{status === 'ready' && kind === 'order' && this.props.mode === 'edit' ? (
<OrderLedgerPanel entries={this.state.ledgerEntries} />
) : null}
</PanelTileGrid>
<ManifestPdfDialog
open={pdfDialogOpen}