u
This commit is contained in:
@@ -118,4 +118,15 @@ export const delivery = {
|
|||||||
return http(`/api/delivery/${id}/file/${fileId}`, { method: 'DELETE' });
|
return http(`/api/delivery/${id}/file/${fileId}`, { method: 'DELETE' });
|
||||||
},
|
},
|
||||||
// #endregion
|
// #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'}
|
{orderCreating ? 'Wird erstellt…' : 'Bestellung erstellen'}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{(kind === 'quote' || kind === 'order') && onPdfCreate && docId != null && Boolean(number) && (
|
{(kind === 'quote' || kind === 'order' || kind === 'delivery') && onPdfCreate && docId != null && Boolean(number) && (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
ledgerSummary: null,
|
ledgerSummary: null,
|
||||||
bookDeliveryDialogOpen: false,
|
bookDeliveryDialogOpen: false,
|
||||||
bookDeliveryPrefillLineId: null,
|
bookDeliveryPrefillLineId: null,
|
||||||
|
pdfCreating: false,
|
||||||
warehouses: warehouseAutomat.state.warehouses || [],
|
warehouses: warehouseAutomat.state.warehouses || [],
|
||||||
};
|
};
|
||||||
this._cancelled = false;
|
this._cancelled = false;
|
||||||
@@ -89,6 +90,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
this.handleDateChange = this.handleDateChange.bind(this);
|
this.handleDateChange = this.handleDateChange.bind(this);
|
||||||
this.handleOpenBookDialog = this.handleOpenBookDialog.bind(this);
|
this.handleOpenBookDialog = this.handleOpenBookDialog.bind(this);
|
||||||
this.handleBookLine = this.handleBookLine.bind(this);
|
this.handleBookLine = this.handleBookLine.bind(this);
|
||||||
|
this.handleCreatePdf = this.handleCreatePdf.bind(this);
|
||||||
this.handleCloseBookDialog = this.handleCloseBookDialog.bind(this);
|
this.handleCloseBookDialog = this.handleCloseBookDialog.bind(this);
|
||||||
this.handleBookSuccess = this.handleBookSuccess.bind(this);
|
this.handleBookSuccess = this.handleBookSuccess.bind(this);
|
||||||
|
|
||||||
@@ -128,7 +130,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
this._warehouseUnsub = warehouseAutomat.subscribe(this, (state) => ({
|
this._warehouseUnsub = warehouseAutomat.subscribe(this, (state) => ({
|
||||||
warehouses: state.warehouses,
|
warehouses: state.warehouses,
|
||||||
}));
|
}));
|
||||||
void warehouseAutomat.actions.load().catch(() => {});
|
void warehouseAutomat.actions.load().catch(() => { });
|
||||||
this._cancelled = false;
|
this._cancelled = false;
|
||||||
if (this.props.docId != null) {
|
if (this.props.docId != null) {
|
||||||
setLastDeliveryPath(`/lieferung/${this.props.docId}`);
|
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() {
|
render() {
|
||||||
const cfg = this.cfg;
|
const cfg = this.cfg;
|
||||||
const {
|
const {
|
||||||
@@ -1151,6 +1179,8 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
externalNumber={externalNumber ?? ''}
|
externalNumber={externalNumber ?? ''}
|
||||||
saving={saving}
|
saving={saving}
|
||||||
pdfUploading={pdfUploading}
|
pdfUploading={pdfUploading}
|
||||||
|
pdfCreating={this.state.pdfCreating}
|
||||||
|
onPdfCreate={this.handleCreatePdf}
|
||||||
attachments={attachments}
|
attachments={attachments}
|
||||||
lines={lines}
|
lines={lines}
|
||||||
onPdfUpload={this.handlePdfUpload}
|
onPdfUpload={this.handlePdfUpload}
|
||||||
@@ -1291,7 +1321,7 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
const hasWarehouse = entry.warehouse_id != null;
|
const hasWarehouse = entry.warehouse_id != null;
|
||||||
const wh = hasWarehouse
|
const wh = hasWarehouse
|
||||||
? (warehouses.find((w) => Number(w.id) === Number(entry.warehouse_id)) ||
|
? (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;
|
: null;
|
||||||
const warehouseName = wh?.name || (hasWarehouse ? `Lager #${entry.warehouse_id}` : '–');
|
const warehouseName = wh?.name || (hasWarehouse ? `Lager #${entry.warehouse_id}` : '–');
|
||||||
|
|
||||||
@@ -1320,7 +1350,6 @@ class LieferungNeuPage extends PureComponent {
|
|||||||
return (
|
return (
|
||||||
<PanelTile
|
<PanelTile
|
||||||
wide={4}
|
wide={4}
|
||||||
title="Buchungen"
|
|
||||||
color={SURFACE_BASE}
|
color={SURFACE_BASE}
|
||||||
sx={{
|
sx={{
|
||||||
gridColumn: { xs: '1 / -1', sm: '1 / -1', md: 'span 4' },
|
gridColumn: { xs: '1 / -1', sm: '1 / -1', md: 'span 4' },
|
||||||
|
|||||||
Reference in New Issue
Block a user