Skip to content

Commit

Permalink
feat: adjusted dashboard to accomodate for delivery information backe…
Browse files Browse the repository at this point in the history
…nd changes
  • Loading branch information
ReneSchroederLJ committed May 14, 2024
1 parent 9684945 commit b4cdf89
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ private boolean validateResponsibility(ReportedDelivery delivery) {
return delivery.getIncoterm() != null && switch (delivery.getIncoterm().getResponsibility()) {
case CUSTOMER ->
delivery.getMaterial().isProductFlag() &&
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns())) &&
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns()));
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns())) &&
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns()));
case SUPPLIER ->
delivery.getMaterial().isMaterialFlag() &&
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns())) &&
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns()));
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns())) &&
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns()));
case PARTIAL ->
(
delivery.getMaterial().isMaterialFlag() &&
Expand Down
16 changes: 7 additions & 9 deletions frontend/src/features/dashboard/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { useProduction } from '../hooks/useProduction';
import { useReportedProduction } from '../hooks/useReportedProduction';

import { requestReportedStocks } from '@services/stocks-service';
import { useReportedDelivery } from '../hooks/useReportedDelivery';
import { useDelivery } from '../hooks/useDelivery';
import { requestReportedDeliveries } from '@services/delivery-service';
import { requestReportedProductions } from '@services/productions-service';
Expand Down Expand Up @@ -104,15 +103,14 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
state.selectedMaterial?.ownMaterialNumber ?? null,
state.selectedSite?.bpns ?? null
);
const { reportedDeliveries } = useReportedDelivery(state.selectedMaterial?.ownMaterialNumber ?? null);

const handleRefresh = () => {
dispatch({ type: 'isRefreshing', payload: true });
Promise.all([
requestReportedStocks(type === 'customer' ? 'material' : 'product', state.selectedMaterial?.ownMaterialNumber ?? null),
requestReportedDeliveries(state.selectedMaterial?.ownMaterialNumber ?? null),
type === 'customer'
? requestReportedProductions(state.selectedMaterial?.ownMaterialNumber ?? null)
requestReportedStocks(type === 'customer' ? 'material' : 'product', state.selectedMaterial?.ownMaterialNumber ?? null),
requestReportedDeliveries(state.selectedMaterial?.ownMaterialNumber ?? null),
type === 'customer'
? requestReportedProductions(state.selectedMaterial?.ownMaterialNumber ?? null)
: requestReportedDemands(state.selectedMaterial?.ownMaterialNumber ?? null)
]).finally(() => dispatch({ type: 'isRefreshing', payload: false }));
};
Expand Down Expand Up @@ -186,7 +184,7 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'incoming', state.selectedSite)}
onDemandClick={openDemandDialog}
demands={demands}
deliveries={reportedDeliveries}
deliveries={deliveries ?? []}
/>
)
) : (
Expand Down Expand Up @@ -245,7 +243,7 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'outgoing', ps)}
onProductionClick={openProductionDialog}
productions={reportedProductions?.filter((p) => p.productionSiteBpns === ps.bpns) ?? []}
deliveries={reportedDeliveries ?? []}
deliveries={deliveries ?? []}
readOnly
/>
)
Expand Down Expand Up @@ -280,7 +278,7 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
}
onSave={refreshDelivery}
delivery={state.delivery}
deliveries={(type === 'customer' ? reportedDeliveries : deliveries) ?? []}
deliveries={deliveries ?? []}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Delivery } from '@models/types/data/delivery';
import { Close, Delete, Save } from '@mui/icons-material';
import { Autocomplete, Box, Button, Dialog, DialogTitle, Grid, Stack, Typography, capitalize } from '@mui/material';
import { deleteDelivery, postDelivery } from '@services/delivery-service';
import { getIncoterm, getUnitOfMeasurement, isValidOrderReference } from '@util/helpers';
import { getUnitOfMeasurement, isValidOrderReference } from '@util/helpers';
import { useEffect, useMemo, useState } from 'react';
import { Notification } from '@models/types/data/notification';
import { INCOTERMS } from '@models/constants/incoterms';
Expand All @@ -46,8 +46,8 @@ const GridItem = ({ label, value }: { label: string; value: string }) => (
</Grid>
);

const createDeliveryColumns = (handleDelete?: (row: Delivery) => void) => {
const columns = [
const createDeliveryColumns = (handleDelete: (row: Delivery) => void) => {
return [
{
field: 'dateOfDeparture',
headerName: 'Departure Time',
Expand Down Expand Up @@ -186,31 +186,25 @@ const createDeliveryColumns = (handleDelete?: (row: Delivery) => void) => {
);
},
},
] as const;
if (handleDelete) {
return [
...columns,
{
field: 'delete',
headerName: '',
sortable: false,
disableColumnMenu: true,
headerAlign: 'center',
type: 'string',
width: 30,
renderCell: (data: { row: Delivery }) => {
return (
<Box display="flex" textAlign="center" alignItems="center" justifyContent="center" width="100%" height="100%">
<Button variant="text" color="error" onClick={() => handleDelete(data.row)}>
<Delete></Delete>
</Button>
</Box>
);
},
{
field: 'delete',
headerName: '',
sortable: false,
disableColumnMenu: true,
headerAlign: 'center',
type: 'string',
width: 30,
renderCell: (data: { row: Delivery }) => {
return (
<Box display="flex" textAlign="center" alignItems="center" justifyContent="center" width="100%" height="100%">
{!data.row.reported && <Button variant="text" color="error" onClick={() => handleDelete(data.row)}>
<Delete></Delete>
</Button>}
</Box>
);
},
] as const;
}
return columns;
},
] as const;
};

const isValidDelivery = (delivery: Partial<Delivery>) =>
Expand Down Expand Up @@ -276,7 +270,7 @@ export const DeliveryInformationModal = ({
...ns,
{
title: 'Delivery Added',
description: 'The Delivery has been saved added',
description: 'The Delivery has been added',
severity: 'success',
},
]);
Expand Down Expand Up @@ -314,7 +308,10 @@ export const DeliveryInformationModal = ({
{mode === 'create' ? (
<>
<GridItem label="Material Number" value={temporaryDelivery.ownMaterialNumber ?? ''} />
<GridItem label="Origin Site" value={temporaryDelivery.originBpns ?? ''} />
<GridItem
label={direction === 'incoming' ? 'Destination Site' : 'Origin Site'}
value={(direction === 'incoming' ? temporaryDelivery.destinationBpns : temporaryDelivery.originBpns) ?? ''}
/>
<Grid item xs={6}>
<Autocomplete
id="departure-type"
Expand Down Expand Up @@ -408,12 +405,16 @@ export const DeliveryInformationModal = ({
disabled={!temporaryDelivery?.partnerBpnl}
isOptionEqualToValue={(option, value) => option?.bpns === value.bpns}
onChange={(_, value) =>
setTemporaryDelivery({ ...temporaryDelivery, destinationBpns: value?.bpns ?? undefined })
setTemporaryDelivery({ ...temporaryDelivery, ...(direction === 'incoming' ? { originBpns: value?.bpns ?? undefined } : { destinationBpns: value?.bpns ?? undefined }) })
}
value={
partners
?.find((s) => s.bpnl === temporaryDelivery?.partnerBpnl)
?.sites.find((s) => s.bpns === temporaryDelivery?.destinationBpns) ?? null
?.sites.find((s) => (
direction === 'incoming'
? s.bpns === temporaryDelivery.originBpns
: s.bpns === temporaryDelivery.destinationBpns) ?? ''
) ?? null
}
renderInput={(params) => (
<Input
Expand Down Expand Up @@ -480,20 +481,17 @@ export const DeliveryInformationModal = ({
id="incoterm"
value={
temporaryDelivery.incoterm
? {
key: temporaryDelivery.incoterm,
value: getIncoterm(temporaryDelivery.incoterm),
}
? INCOTERMS.find((i) => i.key === temporaryDelivery.incoterm) ?? null
: null
}
options={INCOTERMS}
options={INCOTERMS.filter((i) => direction === 'incoming' ? i.responsibility !== 'supplier' : i.responsibility !== 'customer')}
getOptionLabel={(option) => option?.value ?? ''}
renderInput={(params) => (
<Input
{...params}
label="Incoterm*"
placeholder="Select Incoterm"
error={formError && !temporaryDelivery?.measurementUnit}
error={formError && !temporaryDelivery?.incoterm}
/>
)}
onChange={(_, value) => setTemporaryDelivery((curr) => ({ ...curr, incoterm: value?.key }))}
Expand Down Expand Up @@ -557,7 +555,7 @@ export const DeliveryInformationModal = ({
}`}
density="standard"
getRowId={(row) => row.uuid}
columns={createDeliveryColumns(mode === 'view' ? undefined : handleDelete)}
columns={createDeliveryColumns(handleDelete)}
rows={dailyDeliveries}
hideFooter
/>
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/features/dashboard/components/DemandTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,14 @@ export const DemandTable = ({ numberOfDays, stocks, demands, deliveries, site, r
Site:
</Typography>
{site.name} ({site.bpns})
{!readOnly && <Button
variant="contained"
onClick={() =>
onDemandClick({
demandLocationBpns: site.bpns,
}, 'create')
}
sx={{ marginLeft: 'auto' }}
>
<Add></Add> Create Demand
</Button> }
{!readOnly && <Box marginLeft="auto" display="flex" gap="1rem">
<Button variant="contained" onClick={() => onDeliveryClick({ destinationBpns: site.bpns, departureType: 'estimated-departure', arrivalType: 'estimated-arrival' }, 'create')}>
<Add></Add> Add Delivery
</Button>
<Button variant="contained" onClick={() => onDemandClick({ demandLocationBpns: site.bpns }, 'create')} sx={{ marginLeft: 'auto' }} >
<Add></Add> Create Demand
</Button>
</Box>}
</Box>
<TableWithRowHeader
title=""
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/dashboard/hooks/useDelivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useDelivery = (materialNumber: string | null, site: BPNS | null) =>
refresh: refreshDelivery,
} = useFetch<Delivery[]>(
materialNumber && site
? `${config.app.BACKEND_BASE_URL}${config.app.ENDPOINT_DELIVERY}?materialNumber=${materialNumber}&site=${site}`
? `${config.app.BACKEND_BASE_URL}${config.app.ENDPOINT_DELIVERY}?ownMaterialNumber=${materialNumber}&site=${site}`
: undefined
);
return {
Expand Down
33 changes: 0 additions & 33 deletions frontend/src/features/dashboard/hooks/useReportedDelivery.ts

This file was deleted.

19 changes: 18 additions & 1 deletion frontend/src/models/constants/incoterms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,66 @@ under the License.
SPDX-License-Identifier: Apache-2.0
*/

export const INCOTERMS = [
type Incoterm = {
key: string;
value: string;
responsibility: 'customer' | 'partial' | 'supplier';
}

export const INCOTERMS: Incoterm[] = [
{
key: 'EXW',
value: 'EX Works',
responsibility: 'customer',
},
{
key: 'FCA',
value: 'Free Carrier',
responsibility: 'partial',
},
{
key: 'FAS',
value: 'Free Alongside Ship',
responsibility: 'partial',
},
{
key: 'FOB',
value: 'Free On Board',
responsibility: 'partial',
},
{
key: 'CFR',
value: 'Cost and Freight',
responsibility: 'partial',
},
{
key: 'CIF',
value: 'Cost Insurance Freight',
responsibility: 'partial',
},
{
key: 'DAP',
value: 'Delivered At Place',
responsibility: 'supplier',
},
{
key: 'DPU',
value: 'Delivered at Place Unloaded',
responsibility: 'supplier',
},
{
key: 'CPT',
value: 'Carriage Paid To',
responsibility: 'supplier',
},
{
key: 'CIP',
value: 'Carriage Insurance Paid',
responsibility: 'supplier',
},
{
key: 'DDP',
value: 'Delivered Duty Paid',
responsibility: 'supplier',
},
];
1 change: 1 addition & 0 deletions frontend/src/models/types/data/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export type Delivery = {
dateOfArrival: Date;
departureType: DepartureType;
arrivalType: ArrivalType;
reported: boolean;
} & OrderReference;

0 comments on commit b4cdf89

Please sign in to comment.