u
This commit is contained in:
@@ -118,4 +118,15 @@ export const delivery = {
|
||||
return http(`/api/delivery/${id}/file/${fileId}`, { method: 'DELETE' });
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/delivery/:id/pdf
|
||||
* Generates the "Wareneingang" PDF and stores it as a manifest attachment.
|
||||
* → 201 { attachment, fileUrl }
|
||||
*/
|
||||
// #region POST /api/delivery/:id/pdf — createPdf
|
||||
createPdf(id) {
|
||||
return http(`/api/delivery/${id}/pdf`, { method: 'POST' });
|
||||
},
|
||||
// #endregion
|
||||
};
|
||||
|
||||
@@ -530,7 +530,7 @@ class ManifestHeader extends PureComponent {
|
||||
{orderCreating ? 'Wird erstellt…' : 'Bestellung erstellen'}
|
||||
</Button>
|
||||
)}
|
||||
{(kind === 'quote' || kind === 'order') && onPdfCreate && docId != null && Boolean(number) && (
|
||||
{(kind === 'quote' || kind === 'order' || kind === 'delivery') && onPdfCreate && docId != null && Boolean(number) && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outlined"
|
||||
|
||||
@@ -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' },
|
||||
|
||||
Reference in New Issue
Block a user