Compare commits
5 Commits
9b40d1db87
...
c647068067
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c647068067 | ||
|
|
c77f367216 | ||
|
|
578387adca | ||
|
|
037a2b0ae4 | ||
|
|
eb15bcb83b |
@@ -54,4 +54,16 @@ export const shipment = {
|
||||
return http(`/api/shipment/${id}/file/${fileId}`, { method: 'DELETE' });
|
||||
},
|
||||
// #endregion
|
||||
|
||||
// #region POST /api/shipment/:id/pdf — createPdf
|
||||
createPdf(id) {
|
||||
return http(`/api/shipment/${id}/pdf`, { method: 'POST' });
|
||||
},
|
||||
// #endregion
|
||||
|
||||
// #region GET /api/shipment/:id/file/:fileId — getFileUrl
|
||||
getFileUrl(id, fileId) {
|
||||
return `/api/shipment/${encodeURIComponent(id)}/file/${encodeURIComponent(fileId)}`;
|
||||
},
|
||||
// #endregion
|
||||
};
|
||||
|
||||
@@ -4,7 +4,6 @@ import IconButton from '@mui/material/IconButton';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import Switch from '@mui/material/Switch';
|
||||
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined';
|
||||
import DragIndicatorIcon from '@mui/icons-material/DragIndicator';
|
||||
@@ -158,43 +157,39 @@ class CarrierItem extends PureComponent {
|
||||
/>
|
||||
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5, flexShrink: 0 }}>
|
||||
<Tooltip title="Paketverfolgung / Tracking für Sendungen aktivieren">
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={hasPackages}
|
||||
disabled={disabled || !item}
|
||||
onChange={this.handleToggleHasPackages}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Typography variant="caption" sx={{ userSelect: 'none', fontWeight: 500 }}>
|
||||
Pakete
|
||||
</Typography>
|
||||
}
|
||||
sx={{ m: 0, gap: 0.5 }}
|
||||
/>
|
||||
</Tooltip>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={hasPackages}
|
||||
disabled={disabled || !item}
|
||||
onChange={this.handleToggleHasPackages}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Typography variant="caption" sx={{ userSelect: 'none', fontWeight: 500 }}>
|
||||
Pakete
|
||||
</Typography>
|
||||
}
|
||||
sx={{ m: 0, gap: 0.5 }}
|
||||
/>
|
||||
|
||||
<Tooltip title="Für Retouren / Rücksendungen verwenden">
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={isReverse}
|
||||
disabled={disabled || !item}
|
||||
onChange={this.handleToggleIsReverse}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Typography variant="caption" sx={{ userSelect: 'none', fontWeight: 500 }}>
|
||||
Retoure
|
||||
</Typography>
|
||||
}
|
||||
sx={{ m: 0, gap: 0.5 }}
|
||||
/>
|
||||
</Tooltip>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
size="small"
|
||||
checked={isReverse}
|
||||
disabled={disabled || !item}
|
||||
onChange={this.handleToggleIsReverse}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<Typography variant="caption" sx={{ userSelect: 'none', fontWeight: 500 }}>
|
||||
Retoure
|
||||
</Typography>
|
||||
}
|
||||
sx={{ m: 0, gap: 0.5 }}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<IconButton
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
import { PureComponent } from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
import Chip from '@mui/material/Chip';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import ListItemButton from '@mui/material/ListItemButton';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import MenuItem from '@mui/material/MenuItem';
|
||||
import PaymentsIcon from '@mui/icons-material/Payments';
|
||||
import AccountBalanceIcon from '@mui/icons-material/AccountBalance';
|
||||
import PointOfSaleIcon from '@mui/icons-material/PointOfSale';
|
||||
import CreditCardIcon from '@mui/icons-material/CreditCard';
|
||||
import AddIcon from '@mui/icons-material/Add';
|
||||
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined';
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
import SingleLineTextEdit from 'dashgui/SingleLineTextEdit';
|
||||
import FillSpace from 'dashgui/FillSpace';
|
||||
import { PanelTile, PanelTileGrid } from 'dashgui/panels';
|
||||
import BackendError from '../BackendError';
|
||||
import AppDialog from '../AppDialog';
|
||||
import orderAutomat from '../../automats/orderAutomat';
|
||||
import accountAutomat from '../../automats/accountAutomat';
|
||||
import { payment as paymentApi } from '../../api';
|
||||
@@ -31,7 +24,6 @@ import { notifyError } from '../../utils/notify';
|
||||
import { formatPrice } from '../../utils/price';
|
||||
import withNavigate from '../withNavigate';
|
||||
import {
|
||||
formatDate,
|
||||
loadParties,
|
||||
manifestConfig,
|
||||
partyDisplayName,
|
||||
@@ -39,7 +31,6 @@ import {
|
||||
import {
|
||||
YELLOW_PANEL,
|
||||
SURFACE_RAISED,
|
||||
WHITE,
|
||||
} from '../../colors';
|
||||
|
||||
const cfg = manifestConfig('order');
|
||||
@@ -166,175 +157,6 @@ class PaymentTableRow extends PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: <RecordPaymentDialog/>
|
||||
class RecordPaymentDialog extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const orders = props.orders || [];
|
||||
// Prefer unpaid orders
|
||||
const unpaidOrders = orders.filter((o) => {
|
||||
const tot = Number(o.orderTotal) || 0;
|
||||
const pd = Number(o.paidTotal) || 0;
|
||||
return tot === 0 || pd < tot;
|
||||
});
|
||||
|
||||
const selectedOrder = unpaidOrders[0] || orders[0] || null;
|
||||
const remaining = selectedOrder ? Math.max(0, Math.round(((Number(selectedOrder.orderTotal) || 0) - (Number(selectedOrder.paidTotal) || 0)) * 100) / 100) : 0;
|
||||
const accounts = accountAutomat.state.items || [];
|
||||
const defaultAccountId = accounts[0]?.id || 1;
|
||||
|
||||
this.state = {
|
||||
orderId: selectedOrder?.id || '',
|
||||
accountId: defaultAccountId,
|
||||
type: 'transfer',
|
||||
amount: remaining > 0 ? String(remaining) : '',
|
||||
saving: false,
|
||||
};
|
||||
|
||||
this.handleOrderChange = this.handleOrderChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
handleOrderChange(newOrderId) {
|
||||
const order = this.props.orders.find((o) => o.id === Number(newOrderId));
|
||||
const remaining = order ? Math.max(0, Math.round(((Number(order.orderTotal) || 0) - (Number(order.paidTotal) || 0)) * 100) / 100) : 0;
|
||||
this.setState({
|
||||
orderId: newOrderId,
|
||||
amount: remaining > 0 ? String(remaining) : '',
|
||||
});
|
||||
}
|
||||
|
||||
async handleSubmit() {
|
||||
const { onClose, onSuccess } = this.props;
|
||||
const { orderId, accountId, type, amount } = this.state;
|
||||
const numAmount = Number(String(amount).replace(',', '.'));
|
||||
|
||||
if (!orderId) {
|
||||
enqueueSnackbar('Bitte einen Auftrag auswählen.', { variant: 'warning' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Number.isFinite(numAmount) || numAmount <= 0) {
|
||||
enqueueSnackbar('Bitte einen gültigen Betrag größer 0 eingeben.', { variant: 'warning' });
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ saving: true });
|
||||
try {
|
||||
await paymentApi.create(orderId, {
|
||||
accountId: Number(accountId),
|
||||
type,
|
||||
amount: numAmount,
|
||||
});
|
||||
enqueueSnackbar('Zahlungseingang erfolgreich verbucht!', { variant: 'success' });
|
||||
await orderAutomat.actions.reload();
|
||||
onSuccess?.();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
this.setState({ saving: false });
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { open, onClose, orders, partiesById } = this.props;
|
||||
const { orderId, accountId, type, amount, saving } = this.state;
|
||||
const accounts = accountAutomat.state.items || [];
|
||||
|
||||
return (
|
||||
<AppDialog open={open} onClose={onClose} maxWidth="xs" fullWidth>
|
||||
<Box sx={{ p: 2.5 }}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', pb: 2 }}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<PaymentsIcon color="primary" />
|
||||
<Typography variant="h6" sx={{ fontWeight: 600 }}>
|
||||
Zahlungseingang erfassen
|
||||
</Typography>
|
||||
</Box>
|
||||
<IconButton onClick={onClose} size="small">
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, mb: 3 }}>
|
||||
<TextField
|
||||
select
|
||||
label="Auftrag (Manifest)"
|
||||
size="small"
|
||||
value={orderId}
|
||||
onChange={(e) => this.handleOrderChange(e.target.value)}
|
||||
fullWidth
|
||||
>
|
||||
{orders.map((o) => {
|
||||
const party = partiesById[o.entityId];
|
||||
const partyName = partyDisplayName('order', party) || `Kunde #${o.entityId}`;
|
||||
const tot = Number(o.orderTotal) || 0;
|
||||
const pd = Number(o.paidTotal) || 0;
|
||||
const rem = Math.max(0, tot - pd);
|
||||
return (
|
||||
<MenuItem key={o.id} value={o.id}>
|
||||
{o.number} — {partyName} (Offen: {formatPrice(rem)})
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</TextField>
|
||||
|
||||
<TextField
|
||||
select
|
||||
label="Konto / Kasse (account)"
|
||||
size="small"
|
||||
value={accountId}
|
||||
onChange={(e) => this.setState({ accountId: e.target.value })}
|
||||
>
|
||||
{accounts.length > 0 ? (
|
||||
accounts.map((acc) => (
|
||||
<MenuItem key={acc.id} value={acc.id}>
|
||||
{acc.name} ({acc.type})
|
||||
</MenuItem>
|
||||
))
|
||||
) : (
|
||||
<MenuItem value={1}>Standardkonto</MenuItem>
|
||||
)}
|
||||
</TextField>
|
||||
|
||||
<TextField
|
||||
select
|
||||
label="Zahlungsart (type)"
|
||||
size="small"
|
||||
value={type}
|
||||
onChange={(e) => this.setState({ type: e.target.value })}
|
||||
>
|
||||
{PAYMENT_TYPES.map((pt) => (
|
||||
<MenuItem key={pt.value} value={pt.value}>
|
||||
{pt.label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
|
||||
<TextField
|
||||
label="Zahlungsbetrag (€)"
|
||||
size="small"
|
||||
type="number"
|
||||
value={amount}
|
||||
onChange={(e) => this.setState({ amount: e.target.value })}
|
||||
slotProps={{ htmlInput: { min: 0.01, step: 'any' } }}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1.5 }}>
|
||||
<Button variant="outlined" onClick={onClose} disabled={saving}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button variant="contained" onClick={this.handleSubmit} disabled={saving} startIcon={<PaymentsIcon />}>
|
||||
{saving ? 'Wird verbucht…' : 'Zahlung buchen'}
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</AppDialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: <OrderPaymentList/>
|
||||
export class OrderPaymentList extends PureComponent {
|
||||
constructor(props) {
|
||||
@@ -348,7 +170,6 @@ export class OrderPaymentList extends PureComponent {
|
||||
partiesById: {},
|
||||
accountsById: {},
|
||||
busyId: null,
|
||||
recordDialogOpen: false,
|
||||
};
|
||||
this._cancelled = false;
|
||||
this.handleRetry = this.handleRetry.bind(this);
|
||||
@@ -461,7 +282,7 @@ export class OrderPaymentList extends PureComponent {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { status, error, filter, partiesById, accountsById, busyId, recordDialogOpen, items } = this.state;
|
||||
const { status, error, filter, partiesById, accountsById, busyId } = this.state;
|
||||
|
||||
if (status === 'loading' || status === 'idle') {
|
||||
return (
|
||||
@@ -526,15 +347,6 @@ export class OrderPaymentList extends PureComponent {
|
||||
{allPayments.length}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ flex: 1 }} />
|
||||
<Button
|
||||
variant="contained"
|
||||
startIcon={<AddIcon />}
|
||||
onClick={() => this.setState({ recordDialogOpen: true })}
|
||||
sx={{ height: 40 }}
|
||||
>
|
||||
Zahlungseingang erfassen
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
{/* Search Bar */}
|
||||
@@ -594,15 +406,6 @@ export class OrderPaymentList extends PureComponent {
|
||||
/>
|
||||
</PanelTile>
|
||||
</PanelTileGrid>
|
||||
|
||||
{recordDialogOpen && (
|
||||
<RecordPaymentDialog
|
||||
open={recordDialogOpen}
|
||||
orders={items}
|
||||
partiesById={partiesById}
|
||||
onClose={() => this.setState({ recordDialogOpen: false })}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@ import AddIcon from '@mui/icons-material/Add';
|
||||
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined';
|
||||
import CheckCircleOutlineOutlinedIcon from '@mui/icons-material/CheckCircleOutlineOutlined';
|
||||
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
||||
import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
import AppDialog from '../AppDialog';
|
||||
import { shipment as shipmentApi, shipping as shippingApi } from '../../api';
|
||||
import { shipment as shipmentApi, shipping as shippingApi, stock as stockApi } from '../../api';
|
||||
import { notifyError } from '../../utils/notify';
|
||||
import { formatDate } from './manifestConfig';
|
||||
import orderAutomat from '../../automats/orderAutomat';
|
||||
@@ -38,13 +39,11 @@ import { SURFACE_RAISED, WHITE } from '../../colors';
|
||||
class AddPackageDialog extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const carriers = carrierAutomat.state.carriers || [];
|
||||
const carriers = (carrierAutomat.state.carriers || []).filter((c) => !c.isReverse);
|
||||
this.state = {
|
||||
carriers,
|
||||
carrierId: carriers[0]?.id ?? '',
|
||||
trackingCode: '',
|
||||
type: 'parcel',
|
||||
state: 'draft',
|
||||
saving: false,
|
||||
};
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
@@ -52,7 +51,7 @@ class AddPackageDialog extends PureComponent {
|
||||
|
||||
componentDidMount() {
|
||||
this.unsub = carrierAutomat.subscribe(this, (state) => {
|
||||
const carriers = state.carriers || [];
|
||||
const carriers = (state.carriers || []).filter((c) => !c.isReverse);
|
||||
const currentId = this.state.carrierId;
|
||||
const valid = carriers.some((c) => c.id === currentId);
|
||||
return {
|
||||
@@ -61,7 +60,7 @@ class AddPackageDialog extends PureComponent {
|
||||
};
|
||||
});
|
||||
if (carrierAutomat.state.status !== 'ready') {
|
||||
void carrierAutomat.actions.load().catch(() => {});
|
||||
void carrierAutomat.actions.load().catch(() => { });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,18 +70,39 @@ class AddPackageDialog extends PureComponent {
|
||||
|
||||
async handleSubmit() {
|
||||
const { shipment, onClose, onSuccess } = this.props;
|
||||
const { carrierId, trackingCode, type, state } = this.state;
|
||||
if (!shipment?.id || !carrierId) return;
|
||||
const { carriers, carrierId, trackingCode } = this.state;
|
||||
const isShipmentShipped = Boolean(
|
||||
shipment?.state === 'delivered' ||
|
||||
shipment?.state === 'shipped' ||
|
||||
shipment?.state === 'returned' ||
|
||||
shipment?.shippedAt ||
|
||||
(shipment?.state && shipment?.state !== 'new')
|
||||
);
|
||||
if (!shipment?.id || !carrierId || isShipmentShipped) return;
|
||||
|
||||
const selectedCarrier = carriers.find((c) => String(c.id) === String(carrierId));
|
||||
const hasPackages = Boolean(selectedCarrier?.hasPackages);
|
||||
const trimmedTracking = hasPackages && trackingCode ? trackingCode.trim() : undefined;
|
||||
|
||||
this.setState({ saving: true });
|
||||
try {
|
||||
await shippingApi.create(shipment.id, {
|
||||
carrierId: Number(carrierId),
|
||||
trackingCode: trackingCode.trim() || undefined,
|
||||
type,
|
||||
state,
|
||||
trackingCode: trimmedTracking || undefined,
|
||||
type: 'parcel',
|
||||
state: 'draft',
|
||||
});
|
||||
enqueueSnackbar('Paket angelegt.', { variant: 'success' });
|
||||
const oldPdf = (shipment.files || []).find(
|
||||
(f) => f.mimetype === 'application/pdf' || f.name?.toLowerCase().endsWith('.pdf')
|
||||
);
|
||||
if (oldPdf?.id) {
|
||||
try {
|
||||
await shipmentApi.deleteFile(shipment.id, oldPdf.id);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
enqueueSnackbar('Versandart angelegt.', { variant: 'success' });
|
||||
await Promise.all([
|
||||
orderAutomat.actions.reload(),
|
||||
shipmentAutomat.actions.reload(),
|
||||
@@ -97,15 +117,24 @@ class AddPackageDialog extends PureComponent {
|
||||
|
||||
render() {
|
||||
const { open, onClose, shipment } = this.props;
|
||||
const { carriers, carrierId, trackingCode, type, state, saving } = this.state;
|
||||
const canSubmit = Boolean(carrierId) && !saving;
|
||||
const { carriers, carrierId, trackingCode, saving } = this.state;
|
||||
const isShipmentShipped = Boolean(
|
||||
shipment?.state === 'delivered' ||
|
||||
shipment?.state === 'shipped' ||
|
||||
shipment?.state === 'returned' ||
|
||||
shipment?.shippedAt ||
|
||||
(shipment?.state && shipment?.state !== 'new')
|
||||
);
|
||||
const canSubmit = Boolean(carrierId) && !saving && !isShipmentShipped;
|
||||
const selectedCarrier = carriers.find((c) => String(c.id) === String(carrierId));
|
||||
const hasPackages = Boolean(selectedCarrier?.hasPackages);
|
||||
|
||||
return (
|
||||
<AppDialog open={open} onClose={onClose} maxWidth="xs" fullWidth>
|
||||
<Box sx={{ p: 2.5 }}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', pb: 2 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 600 }}>
|
||||
Paket zu Lieferschein hinzufügen
|
||||
Versand hinzufügen
|
||||
</Typography>
|
||||
<IconButton onClick={onClose} size="small">
|
||||
<CloseIcon />
|
||||
@@ -118,14 +147,14 @@ class AddPackageDialog extends PureComponent {
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, mb: 3 }}>
|
||||
<TextField
|
||||
select
|
||||
label="Versandart (Carrier)"
|
||||
label="Versandart"
|
||||
size="small"
|
||||
value={carrierId}
|
||||
onChange={(e) => this.setState({ carrierId: e.target.value })}
|
||||
error={carriers.length === 0}
|
||||
helperText={
|
||||
carriers.length === 0
|
||||
? 'Keine Versandarten eingerichtet (unter Auftrag → Versandarten anlegen)'
|
||||
? 'Keine Versandarten eingerichtet'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
@@ -136,38 +165,15 @@ class AddPackageDialog extends PureComponent {
|
||||
))}
|
||||
</TextField>
|
||||
|
||||
<TextField
|
||||
label="Tracking-Code / Sendungsnummer"
|
||||
size="small"
|
||||
value={trackingCode}
|
||||
onChange={(e) => this.setState({ trackingCode: e.target.value })}
|
||||
placeholder="z.B. 00340434234234234"
|
||||
/>
|
||||
|
||||
<TextField
|
||||
select
|
||||
label="Paketart"
|
||||
size="small"
|
||||
value={type}
|
||||
onChange={(e) => this.setState({ type: e.target.value })}
|
||||
>
|
||||
<MenuItem value="parcel">Paket (Parcel)</MenuItem>
|
||||
<MenuItem value="pallet">Palette (Pallet)</MenuItem>
|
||||
<MenuItem value="letter">Brief / Dokument</MenuItem>
|
||||
</TextField>
|
||||
|
||||
<TextField
|
||||
select
|
||||
label="Status"
|
||||
size="small"
|
||||
value={state}
|
||||
onChange={(e) => this.setState({ state: e.target.value })}
|
||||
helperText={state === 'shipped' ? 'Bucht bei Auswahl direkt das Lager ab.' : undefined}
|
||||
>
|
||||
<MenuItem value="draft">Entwurf (draft)</MenuItem>
|
||||
<MenuItem value="packed">Gepackt (packed)</MenuItem>
|
||||
<MenuItem value="shipped">Versendet (shipped — Lagerabbuchung)</MenuItem>
|
||||
</TextField>
|
||||
{hasPackages && (
|
||||
<TextField
|
||||
label="Referenz"
|
||||
size="small"
|
||||
value={trackingCode}
|
||||
onChange={(e) => this.setState({ trackingCode: e.target.value })}
|
||||
placeholder="z.B. Sendungsnummer, Paket-ID oder Referenz"
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1.5 }}>
|
||||
@@ -175,7 +181,7 @@ class AddPackageDialog extends PureComponent {
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button variant="contained" onClick={this.handleSubmit} disabled={!canSubmit}>
|
||||
{saving ? 'Wird gespeichert…' : 'Paket anlegen'}
|
||||
{saving ? 'Wird gespeichert…' : 'Hinzufügen'}
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -196,11 +202,14 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
error: null,
|
||||
addPackageDialogOpen: false,
|
||||
busyAction: false,
|
||||
pdfLoading: false,
|
||||
};
|
||||
this.handleRefresh = this.handleRefresh.bind(this);
|
||||
this.handleDeletePackage = this.handleDeletePackage.bind(this);
|
||||
this.handleMarkPackageShipped = this.handleMarkPackageShipped.bind(this);
|
||||
this.handleStateChange = this.handleStateChange.bind(this);
|
||||
this.handleDeleteShipment = this.handleDeleteShipment.bind(this);
|
||||
this.handleOpenPdf = this.handleOpenPdf.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@@ -240,11 +249,21 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
// #endregion
|
||||
|
||||
async handleDeletePackage(pkg) {
|
||||
if (!window.confirm(`Paket „#${pkg.number || pkg.id}“ wirklich löschen?`)) return;
|
||||
if (!window.confirm(`Versandart „#${pkg.number || pkg.id}“ wirklich löschen?`)) return;
|
||||
this.setState({ busyAction: true });
|
||||
try {
|
||||
await shippingApi.delete(pkg.id);
|
||||
enqueueSnackbar('Paket gelöscht.', { variant: 'success' });
|
||||
const oldPdf = (this.state.shipment?.files || []).find(
|
||||
(f) => f.mimetype === 'application/pdf' || f.name?.toLowerCase().endsWith('.pdf')
|
||||
);
|
||||
if (oldPdf?.id) {
|
||||
try {
|
||||
await shipmentApi.deleteFile(this.state.shipment.id, oldPdf.id);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
enqueueSnackbar('Versandart gelöscht.', { variant: 'success' });
|
||||
await Promise.all([
|
||||
orderAutomat.actions.reload(),
|
||||
shipmentAutomat.actions.reload(),
|
||||
@@ -282,6 +301,29 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
|
||||
this.setState({ busyAction: true });
|
||||
try {
|
||||
if (newState === 'delivered') {
|
||||
// 1. Mark any unshipped packages as shipped (triggers backend stock deduction for linked shippings)
|
||||
const unshippedPackages = (this.state.shipment?.shippings || []).filter(
|
||||
(p) => p.state !== 'shipped'
|
||||
);
|
||||
for (const pkg of unshippedPackages) {
|
||||
try {
|
||||
await shippingApi.update(pkg.id, { state: 'shipped' });
|
||||
} catch (err) {
|
||||
console.warn('Could not mark shipping as shipped:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Ensure stock deduction is executed via stock.ship for the shipment lines
|
||||
try {
|
||||
await stockApi.ship({ shipmentId });
|
||||
} catch (err) {
|
||||
if (!err?.message?.toLowerCase().includes('already shipped')) {
|
||||
console.warn('Stock ship warning:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await shipmentApi.update(shipmentId, { state: newState });
|
||||
this.setState((prev) => ({
|
||||
shipment: { ...prev.shipment, state: newState },
|
||||
@@ -293,6 +335,7 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
shipmentAutomat.actions.reload(),
|
||||
]);
|
||||
this.props.onChanged?.();
|
||||
await this.handleRefresh();
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
} finally {
|
||||
@@ -300,14 +343,85 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: calls shipmentApi.delete
|
||||
// #region DELETE /api/shipment/:id — delete shipment
|
||||
async handleDeleteShipment() {
|
||||
const { shipment } = this.state;
|
||||
if (!shipment?.id) return;
|
||||
|
||||
const label = shipment.number || `Lieferschein #${shipment.id}`;
|
||||
if (!window.confirm(`Möchten Sie den ${label} wirklich löschen?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ busyAction: true });
|
||||
try {
|
||||
await shipmentApi.delete(shipment.id);
|
||||
enqueueSnackbar(`${label} gelöscht.`, { variant: 'success' });
|
||||
await Promise.all([
|
||||
orderAutomat.actions.reload(),
|
||||
shipmentAutomat.actions.reload(),
|
||||
]);
|
||||
this.props.onChanged?.();
|
||||
this.props.onClose();
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
this.setState({ busyAction: false });
|
||||
}
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// MARK: calls shipmentApi.createPdf and shipmentApi.getFileUrl
|
||||
// #region POST /api/shipment/:id/pdf & GET file — open PDF
|
||||
async handleOpenPdf() {
|
||||
const { shipment } = this.state;
|
||||
if (!shipment?.id) return;
|
||||
|
||||
this.setState({ pdfLoading: true });
|
||||
try {
|
||||
const existingPdf = (shipment.files || []).find(
|
||||
(f) => f.mimetype === 'application/pdf' || f.name?.toLowerCase().endsWith('.pdf')
|
||||
);
|
||||
|
||||
let targetUrl = null;
|
||||
if (existingPdf) {
|
||||
targetUrl = shipmentApi.getFileUrl(shipment.id, existingPdf.fileId || existingPdf.id);
|
||||
} else {
|
||||
const res = await shipmentApi.createPdf(shipment.id);
|
||||
const rawUrl = res?.fileUrl || (res?.attachment ? shipmentApi.getFileUrl(shipment.id, res.attachment.fileId || res.attachment.id) : null);
|
||||
targetUrl = rawUrl ? (rawUrl.startsWith('/api') ? rawUrl : `/api${rawUrl}`) : null;
|
||||
await this.handleRefresh();
|
||||
}
|
||||
|
||||
if (targetUrl) {
|
||||
window.open(targetUrl, '_blank');
|
||||
} else {
|
||||
enqueueSnackbar('PDF-URL konnte nicht geladen werden.', { variant: 'error' });
|
||||
}
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
} finally {
|
||||
this.setState({ pdfLoading: false });
|
||||
}
|
||||
}
|
||||
// #endregion
|
||||
|
||||
render() {
|
||||
const { open, onClose } = this.props;
|
||||
const { shipment, loading, error, addPackageDialogOpen, busyAction } = this.state;
|
||||
const { shipment, loading, error, addPackageDialogOpen, busyAction, pdfLoading } = this.state;
|
||||
|
||||
if (!shipment) return null;
|
||||
|
||||
const shLines = Array.isArray(shipment.lines) ? shipment.lines : [];
|
||||
const shPackages = Array.isArray(shipment.shippings) ? shipment.shippings : [];
|
||||
const carriers = carrierAutomat.state.carriers || [];
|
||||
const isShipmentShipped = Boolean(
|
||||
shipment.state === 'delivered' ||
|
||||
shipment.state === 'shipped' ||
|
||||
shipment.state === 'returned' ||
|
||||
shipment.shippedAt ||
|
||||
(shipment.state && shipment.state !== 'new')
|
||||
);
|
||||
|
||||
return (
|
||||
<AppDialog open={open} onClose={onClose} maxWidth="md" fullWidth>
|
||||
@@ -383,10 +497,11 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
variant="outlined"
|
||||
startIcon={<AddIcon />}
|
||||
onClick={() => this.setState({ addPackageDialogOpen: true })}
|
||||
disabled={busyAction}
|
||||
disabled={busyAction || isShipmentShipped}
|
||||
title={isShipmentShipped ? 'Lieferschein ist bereits versendet' : undefined}
|
||||
sx={{ textTransform: 'none', fontWeight: 600, height: 28, fontSize: '0.75rem' }}
|
||||
>
|
||||
Paket hinzufügen
|
||||
Versand hinzufügen
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
@@ -394,6 +509,8 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
<Stack spacing={1}>
|
||||
{shPackages.map((pkg) => {
|
||||
const isShipped = pkg.state === 'shipped';
|
||||
const carrierObj = carriers.find((c) => Number(c.id) === Number(pkg.carrierId));
|
||||
const carrierHasPackages = carrierObj ? Boolean(carrierObj.hasPackages) : false;
|
||||
return (
|
||||
<Box
|
||||
key={pkg.id}
|
||||
@@ -412,7 +529,7 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
<Chip size="small" label={`#${pkg.number || pkg.id}`} sx={{ fontWeight: 700 }} />
|
||||
<Box>
|
||||
<Typography variant="subtitle2" sx={{ fontWeight: 700 }}>
|
||||
{pkg.carrier || 'DHL'} ({pkg.type === 'pallet' ? 'Palette' : 'Paket'})
|
||||
{pkg.carrier || 'Versand'}
|
||||
</Typography>
|
||||
{pkg.trackingCode ? (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5, mt: 0.25 }}>
|
||||
@@ -423,42 +540,34 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
size="small"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(pkg.trackingCode);
|
||||
enqueueSnackbar('Tracking-Code kopiert!', { variant: 'info' });
|
||||
enqueueSnackbar('Referenz kopiert!', { variant: 'info' });
|
||||
}}
|
||||
sx={{ p: 0.25 }}
|
||||
>
|
||||
<ContentCopyIcon sx={{ fontSize: 13 }} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
) : (
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
Ohne Tracking
|
||||
</Typography>
|
||||
)}
|
||||
) : null}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
{isShipped ? (
|
||||
<Chip
|
||||
size="small"
|
||||
color="success"
|
||||
icon={<CheckCircleOutlineOutlinedIcon />}
|
||||
label="Versendet (Lager abgebucht)"
|
||||
sx={{ fontWeight: 600 }}
|
||||
/>
|
||||
null
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
size="small"
|
||||
variant="contained"
|
||||
color="success"
|
||||
disabled={busyAction}
|
||||
onClick={() => this.handleMarkPackageShipped(pkg)}
|
||||
sx={{ textTransform: 'none', py: 0.25, px: 1, height: 26, fontSize: '0.75rem' }}
|
||||
>
|
||||
Als versendet buchen
|
||||
</Button>
|
||||
{carrierHasPackages && (
|
||||
<Button
|
||||
size="small"
|
||||
variant="contained"
|
||||
color="success"
|
||||
disabled={busyAction}
|
||||
onClick={() => this.handleMarkPackageShipped(pkg)}
|
||||
sx={{ textTransform: 'none', py: 0.25, px: 1, height: 26, fontSize: '0.75rem' }}
|
||||
>
|
||||
Als versendet buchen
|
||||
</Button>
|
||||
)}
|
||||
<IconButton
|
||||
size="small"
|
||||
color="error"
|
||||
@@ -478,51 +587,78 @@ export default class ShipmentDetailDialog extends PureComponent {
|
||||
</Box>
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions sx={{ p: 2, justifyContent: 'flex-end' }}>
|
||||
{(!shipment.state || shipment.state === 'new') && (
|
||||
<DialogActions sx={{ p: 2, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="error"
|
||||
startIcon={<DeleteOutlinedIcon />}
|
||||
disabled={busyAction || shipment.state === 'delivered'}
|
||||
onClick={this.handleDeleteShipment}
|
||||
title={shipment.state === 'delivered' ? 'Bereits versendete Lieferscheine können nicht gelöscht werden' : 'Lieferschein löschen'}
|
||||
sx={{ textTransform: 'none', fontWeight: 600 }}
|
||||
>
|
||||
Lieferschein löschen
|
||||
</Button>
|
||||
|
||||
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'center' }}>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
disabled={busyAction}
|
||||
onClick={() => this.handleStateChange('delivered')}
|
||||
sx={{ textTransform: 'none', fontWeight: 700 }}
|
||||
>
|
||||
{busyAction ? 'Wird versendet…' : 'Versenden'}
|
||||
</Button>
|
||||
)}
|
||||
{shipment.state === 'delivered' && (
|
||||
<Button
|
||||
variant="contained"
|
||||
color="warning"
|
||||
disabled={busyAction}
|
||||
onClick={() => this.handleStateChange('returned')}
|
||||
sx={{ textTransform: 'none', fontWeight: 700 }}
|
||||
>
|
||||
{busyAction ? 'Wird gebucht…' : 'Retoure'}
|
||||
</Button>
|
||||
)}
|
||||
{shipment.state === 'returned' && (
|
||||
<Chip
|
||||
label="Retoure"
|
||||
color="error"
|
||||
variant="outlined"
|
||||
sx={{ fontWeight: 700, height: 28, fontSize: '0.8rem' }}
|
||||
/>
|
||||
)}
|
||||
color="inherit"
|
||||
startIcon={pdfLoading ? <CircularProgress size={16} color="inherit" /> : <PictureAsPdfIcon sx={{ color: 'error.main' }} />}
|
||||
disabled={busyAction || pdfLoading}
|
||||
onClick={this.handleOpenPdf}
|
||||
sx={{ textTransform: 'none', fontWeight: 600 }}
|
||||
>
|
||||
{pdfLoading ? 'PDF wird geladen…' : 'PDF'}
|
||||
</Button>
|
||||
|
||||
{(!shipment.state || shipment.state === 'new') && (
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
disabled={busyAction}
|
||||
onClick={() => this.handleStateChange('delivered')}
|
||||
sx={{ textTransform: 'none', fontWeight: 700 }}
|
||||
>
|
||||
{busyAction ? 'Wird versendet…' : 'Versenden'}
|
||||
</Button>
|
||||
)}
|
||||
{shipment.state === 'delivered' && (
|
||||
<Button
|
||||
variant="contained"
|
||||
color="warning"
|
||||
disabled={busyAction}
|
||||
onClick={() => this.handleStateChange('returned')}
|
||||
sx={{ textTransform: 'none', fontWeight: 700 }}
|
||||
>
|
||||
{busyAction ? 'Wird gebucht…' : 'Retoure'}
|
||||
</Button>
|
||||
)}
|
||||
{shipment.state === 'returned' && (
|
||||
<Chip
|
||||
label="Retoure"
|
||||
color="error"
|
||||
variant="outlined"
|
||||
sx={{ fontWeight: 700, height: 28, fontSize: '0.8rem' }}
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
</DialogActions>
|
||||
|
||||
{addPackageDialogOpen && (
|
||||
<AddPackageDialog
|
||||
open={addPackageDialogOpen}
|
||||
shipment={shipment}
|
||||
onClose={() => this.setState({ addPackageDialogOpen: false })}
|
||||
onSuccess={async () => {
|
||||
this.props.onChanged?.();
|
||||
await this.handleRefresh();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</AppDialog>
|
||||
{
|
||||
addPackageDialogOpen && (
|
||||
<AddPackageDialog
|
||||
open={addPackageDialogOpen}
|
||||
shipment={shipment}
|
||||
onClose={() => this.setState({ addPackageDialogOpen: false })}
|
||||
onSuccess={async () => {
|
||||
this.props.onChanged?.();
|
||||
await this.handleRefresh();
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
</AppDialog >
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ export const SUB_NAV = {
|
||||
label: 'Zahlungen',
|
||||
title: 'Zahlungen',
|
||||
icon: PaymentsIcon,
|
||||
help: 'Zahlungseingänge erfassen und Auftragszahlungen überwachen',
|
||||
help: 'Auftragszahlungen und Zahlungsjournal überwachen',
|
||||
},
|
||||
{
|
||||
segment: 'versandarten',
|
||||
|
||||
Reference in New Issue
Block a user