This commit is contained in:
seb
2026-10-17 19:51:27 +02:00
parent 7080382f56
commit c332be8916
3 changed files with 44 additions and 4 deletions

View File

@@ -80,6 +80,7 @@ class LieferungNeuPage extends PureComponent {
ledgerSummary: null,
bookDeliveryDialogOpen: false,
bookDeliveryPrefillLineId: null,
pdfCreating: false,
warehouses: warehouseAutomat.state.warehouses || [],
};
this._cancelled = false;
@@ -89,6 +90,7 @@ class LieferungNeuPage extends PureComponent {
this.handleDateChange = this.handleDateChange.bind(this);
this.handleOpenBookDialog = this.handleOpenBookDialog.bind(this);
this.handleBookLine = this.handleBookLine.bind(this);
this.handleCreatePdf = this.handleCreatePdf.bind(this);
this.handleCloseBookDialog = this.handleCloseBookDialog.bind(this);
this.handleBookSuccess = this.handleBookSuccess.bind(this);
@@ -128,7 +130,7 @@ class LieferungNeuPage extends PureComponent {
this._warehouseUnsub = warehouseAutomat.subscribe(this, (state) => ({
warehouses: state.warehouses,
}));
void warehouseAutomat.actions.load().catch(() => {});
void warehouseAutomat.actions.load().catch(() => { });
this._cancelled = false;
if (this.props.docId != null) {
setLastDeliveryPath(`/lieferung/${this.props.docId}`);
@@ -1098,6 +1100,32 @@ class LieferungNeuPage extends PureComponent {
}
}
/** Generates the "Wareneingang" PDF server-side, stores it and shows it among the attachments. */
async handleCreatePdf(e) {
e?.preventDefault?.();
e?.stopPropagation?.();
const { docId } = this.props;
if (docId == null || this.state.pdfCreating || this.state.saving) return;
this.setState({ pdfCreating: true });
try {
const res = await deliveryApi.createPdf(docId);
requireObject(res, 'POST /api/delivery/:id/pdf');
const getRes = await deliveryApi.get(docId);
const doc = getRes?.delivery;
if (doc?.files && !this._cancelled) {
const attachments = await restoreAttachmentsFromApi(doc.files, this.state.attachments);
this.automat.actions.setAttachments(attachments);
}
enqueueSnackbar('Wareneingang-PDF erfolgreich erstellt.', { variant: 'success' });
} catch (err) {
if (!this._cancelled) notifyError(err);
} finally {
if (!this._cancelled) this.setState({ pdfCreating: false });
}
}
render() {
const cfg = this.cfg;
const {
@@ -1151,6 +1179,8 @@ class LieferungNeuPage extends PureComponent {
externalNumber={externalNumber ?? ''}
saving={saving}
pdfUploading={pdfUploading}
pdfCreating={this.state.pdfCreating}
onPdfCreate={this.handleCreatePdf}
attachments={attachments}
lines={lines}
onPdfUpload={this.handlePdfUpload}
@@ -1291,7 +1321,7 @@ class LieferungNeuPage extends PureComponent {
const hasWarehouse = entry.warehouse_id != null;
const wh = hasWarehouse
? (warehouses.find((w) => Number(w.id) === Number(entry.warehouse_id)) ||
warehouseAutomat.state.warehouses?.find((w) => Number(w.id) === Number(entry.warehouse_id)))
warehouseAutomat.state.warehouses?.find((w) => Number(w.id) === Number(entry.warehouse_id)))
: null;
const warehouseName = wh?.name || (hasWarehouse ? `Lager #${entry.warehouse_id}` : '–');
@@ -1320,7 +1350,6 @@ class LieferungNeuPage extends PureComponent {
return (
<PanelTile
wide={4}
title="Buchungen"
color={SURFACE_BASE}
sx={{
gridColumn: { xs: '1 / -1', sm: '1 / -1', md: 'span 4' },