u
This commit is contained in:
@@ -4,7 +4,7 @@ import CircularProgress from '@mui/material/CircularProgress';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
import BackendError from '../BackendError';
|
||||
import { PanelTileGrid } from 'dashgui/panels';
|
||||
import { delivery as deliveryApi } from '../../api';
|
||||
import { delivery as deliveryApi, quote as quoteApi } from '../../api';
|
||||
import { requireArray, requireDefined, requireObject } from '../../utils/apiShape';
|
||||
import { backendErrorFrom } from '../../utils/backendError';
|
||||
import { notifyError } from '../../utils/notify';
|
||||
@@ -73,6 +73,7 @@ class ManifestForm extends PureComponent {
|
||||
dirtySummary: initialEdit?.dirtySummary || [],
|
||||
saving: false,
|
||||
pdfUploading: false,
|
||||
pdfCreating: false,
|
||||
pdfDialogOpen: false,
|
||||
pdfDialogData: null,
|
||||
pdfFileName: '',
|
||||
@@ -98,6 +99,8 @@ class ManifestForm extends PureComponent {
|
||||
this.handleRemoveAllLines = this.handleRemoveAllLines.bind(this);
|
||||
this.handleSave = this.handleSave.bind(this);
|
||||
this.handlePdfUpload = this.handlePdfUpload.bind(this);
|
||||
this.handleCreatePdf = this.handleCreatePdf.bind(this);
|
||||
this.handleAttachmentDelete = this.handleAttachmentDelete.bind(this);
|
||||
this.handleClosePdfDialog = this.handleClosePdfDialog.bind(this);
|
||||
this.handleAbortParse = this.handleAbortParse.bind(this);
|
||||
}
|
||||
@@ -806,6 +809,83 @@ class ManifestForm extends PureComponent {
|
||||
this.setState({ pdfDialogOpen: false, pdfUploading: false });
|
||||
}
|
||||
|
||||
async handleCreatePdf() {
|
||||
const { docId } = this.props;
|
||||
if (this.state.pdfCreating || this.state.saving) return;
|
||||
if (docId == null) return;
|
||||
|
||||
if (this.state.isDirty) {
|
||||
await this.handleSave();
|
||||
if (this.state.isDirty) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({ pdfCreating: true });
|
||||
try {
|
||||
const res = await quoteApi.createPdf(docId);
|
||||
requireObject(res, 'POST /api/quote/:id/pdf');
|
||||
|
||||
const quoteRes = await quoteApi.get(docId);
|
||||
if (quoteRes?.quote?.files && !this._cancelled) {
|
||||
const attachments = await restoreAttachmentsFromApi(
|
||||
quoteRes.quote.files,
|
||||
this.state.attachments,
|
||||
);
|
||||
this.setState({ attachments });
|
||||
if (this.editAutomat) {
|
||||
this.editAutomat.actions.updateDraft({ attachments });
|
||||
}
|
||||
}
|
||||
|
||||
enqueueSnackbar('Angebot-PDF erfolgreich erstellt.', { variant: 'success' });
|
||||
|
||||
const fileUrl =
|
||||
res.fileUrl ||
|
||||
(res.attachment?.fileId
|
||||
? `/api/quote/${docId}/file/${res.attachment.fileId}`
|
||||
: null);
|
||||
if (fileUrl) {
|
||||
window.open(fileUrl, '_blank');
|
||||
}
|
||||
} catch (err) {
|
||||
if (!this._cancelled) {
|
||||
notifyError(err);
|
||||
}
|
||||
} finally {
|
||||
if (!this._cancelled) {
|
||||
this.setState({ pdfCreating: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handleAttachmentDelete(attachment) {
|
||||
if (!attachment) return;
|
||||
const targetId = attachment.id ?? attachment.fileId;
|
||||
const { docId } = this.props;
|
||||
|
||||
const nextAttachments = (this.state.attachments || []).filter(
|
||||
(a) => (a.id ?? a.fileId) !== targetId && a !== attachment,
|
||||
);
|
||||
this.setState({ attachments: nextAttachments });
|
||||
|
||||
if (this.editAutomat) {
|
||||
this.editAutomat.actions.updateDraft({ attachments: nextAttachments });
|
||||
}
|
||||
|
||||
if (docId != null && targetId != null && attachment.isPersisted) {
|
||||
try {
|
||||
const api = apiFor(this.cfg);
|
||||
if (typeof api.deleteFile === 'function') {
|
||||
await api.deleteFile(docId, targetId);
|
||||
enqueueSnackbar('Anhang gelöscht.', { variant: 'success' });
|
||||
}
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handleSave() {
|
||||
const { mode, docId } = this.props;
|
||||
const cfg = this.cfg;
|
||||
@@ -965,12 +1045,17 @@ class ManifestForm extends PureComponent {
|
||||
externalNumber={externalNumber}
|
||||
saving={saving}
|
||||
pdfUploading={pdfUploading}
|
||||
pdfCreating={this.state.pdfCreating}
|
||||
lines={lines}
|
||||
attachments={this.state.attachments}
|
||||
docId={this.props.docId}
|
||||
isDirty={this.state.isDirty}
|
||||
dirtyFields={this.state.dirtyFields}
|
||||
dirtySummary={this.state.dirtySummary}
|
||||
onRestore={this.props.mode === 'edit' && this.state.isDirty ? this.handleRestore : undefined}
|
||||
onPdfUpload={kind === 'delivery' ? this.handlePdfUpload : undefined}
|
||||
onPdfDelete={this.handleAttachmentDelete}
|
||||
onPdfCreate={kind === 'quote' ? this.handleCreatePdf : undefined}
|
||||
onSave={this.handleSave}
|
||||
onPartyChange={this.handlePartyChange}
|
||||
onDateChange={this.handleDateChange}
|
||||
|
||||
Reference in New Issue
Block a user