feat: empty boxes, ids for shipping pdfs
This commit is contained in:
		@@ -6,7 +6,7 @@ import type { ProductSchema } from './ProductSchema';
 | 
				
			|||||||
export type BoxSchema = {
 | 
					export type BoxSchema = {
 | 
				
			||||||
    id: number;
 | 
					    id: number;
 | 
				
			||||||
    quantity: number;
 | 
					    quantity: number;
 | 
				
			||||||
    product: ProductSchema;
 | 
					    product: (ProductSchema | null);
 | 
				
			||||||
    palletId: (number | null);
 | 
					    palletId: (number | null);
 | 
				
			||||||
    dealId: (number | null);
 | 
					    dealId: (number | null);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,6 @@
 | 
				
			|||||||
/* tslint:disable */
 | 
					/* tslint:disable */
 | 
				
			||||||
/* eslint-disable */
 | 
					/* eslint-disable */
 | 
				
			||||||
export type CreateBoxInDealSchema = {
 | 
					export type CreateBoxInDealSchema = {
 | 
				
			||||||
    productId: (number | null);
 | 
					 | 
				
			||||||
    quantity: (number | null);
 | 
					 | 
				
			||||||
    dealId: (number | null);
 | 
					    dealId: (number | null);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,6 @@
 | 
				
			|||||||
/* tslint:disable */
 | 
					/* tslint:disable */
 | 
				
			||||||
/* eslint-disable */
 | 
					/* eslint-disable */
 | 
				
			||||||
export type CreateBoxInPalletSchema = {
 | 
					export type CreateBoxInPalletSchema = {
 | 
				
			||||||
    productId: (number | null);
 | 
					 | 
				
			||||||
    quantity: (number | null);
 | 
					 | 
				
			||||||
    palletId: (number | null);
 | 
					    palletId: (number | null);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ type Props = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BoxesTable = ({ items }: Props) => {
 | 
					const BoxesTable = ({ items }: Props) => {
 | 
				
			||||||
    const columns = useShippingTableColumns<BoxSchema>();
 | 
					    const columns = useShippingTableColumns<BoxSchema>({ isBox: true });
 | 
				
			||||||
    const { update } = useUpdateDeal();
 | 
					    const { update } = useUpdateDeal();
 | 
				
			||||||
    const { selectedDeal: deal } = useDealPageContext();
 | 
					    const { selectedDeal: deal } = useDealPageContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -42,7 +42,7 @@ const BoxesTable = ({ items }: Props) => {
 | 
				
			|||||||
                isBox: true,
 | 
					                isBox: true,
 | 
				
			||||||
                shippingData: {
 | 
					                shippingData: {
 | 
				
			||||||
                    boxId: box.id,
 | 
					                    boxId: box.id,
 | 
				
			||||||
                    productId: box.product.id,
 | 
					                    productId: box.product?.id,
 | 
				
			||||||
                    quantity: box.quantity,
 | 
					                    quantity: box.quantity,
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
@@ -58,7 +58,6 @@ const BoxesTable = ({ items }: Props) => {
 | 
				
			|||||||
                    enableSorting: false,
 | 
					                    enableSorting: false,
 | 
				
			||||||
                    enableColumnActions: false,
 | 
					                    enableColumnActions: false,
 | 
				
			||||||
                    enableRowActions: true,
 | 
					                    enableRowActions: true,
 | 
				
			||||||
                    enableRowNumbers: true,
 | 
					 | 
				
			||||||
                    positionActionsColumn: "last",
 | 
					                    positionActionsColumn: "last",
 | 
				
			||||||
                    renderRowActions: ({ row }) => (
 | 
					                    renderRowActions: ({ row }) => (
 | 
				
			||||||
                        <Flex gap="md">
 | 
					                        <Flex gap="md">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ type Props = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const ShippingProductsTable = ({ items }: Props) => {
 | 
					const ShippingProductsTable = ({ items }: Props) => {
 | 
				
			||||||
    const columns = useShippingTableColumns<ShippingProductSchema>();
 | 
					    const columns = useShippingTableColumns<ShippingProductSchema>({ isBox: false });
 | 
				
			||||||
    const { update } = useUpdateDeal();
 | 
					    const { update } = useUpdateDeal();
 | 
				
			||||||
    const { selectedDeal: deal } = useDealPageContext();
 | 
					    const { selectedDeal: deal } = useDealPageContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -44,7 +44,7 @@ const ShippingProductsTable = ({ items }: Props) => {
 | 
				
			|||||||
                    shippingProductId: shippingProduct.id,
 | 
					                    shippingProductId: shippingProduct.id,
 | 
				
			||||||
                    productId: shippingProduct.product.id,
 | 
					                    productId: shippingProduct.product.id,
 | 
				
			||||||
                    quantity: shippingProduct.quantity,
 | 
					                    quantity: shippingProduct.quantity,
 | 
				
			||||||
                }
 | 
					                },
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,13 +22,13 @@ const ShippingTree = () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const getPallets = () => {
 | 
					    const getPallets = () => {
 | 
				
			||||||
        const sortedPallets = sortById(deal?.pallets) as PalletSchema[];
 | 
					        const sortedPallets = sortById(deal?.pallets) as PalletSchema[];
 | 
				
			||||||
        const pallets = sortedPallets?.map(((pallet, index) => {
 | 
					        const pallets = sortedPallets?.map((pallet => {
 | 
				
			||||||
            palletIds.push(pallet.id.toString());
 | 
					            palletIds.push(pallet.id.toString());
 | 
				
			||||||
            return (
 | 
					            return (
 | 
				
			||||||
                <Accordion.Item key={pallet.id} value={pallet.id.toString()}>
 | 
					                <Accordion.Item key={pallet.id} value={pallet.id.toString()}>
 | 
				
			||||||
                    <Center>
 | 
					                    <Center>
 | 
				
			||||||
                        <Accordion.Control icon={<IconSpace />}>
 | 
					                        <Accordion.Control icon={<IconSpace />}>
 | 
				
			||||||
                            Паллет {index + 1}
 | 
					                            Паллет - П{pallet.id}
 | 
				
			||||||
                        </Accordion.Control>
 | 
					                        </Accordion.Control>
 | 
				
			||||||
                        {removePalletButton(pallet.id)}
 | 
					                        {removePalletButton(pallet.id)}
 | 
				
			||||||
                    </Center>
 | 
					                    </Center>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,20 +1,34 @@
 | 
				
			|||||||
import { useMemo } from "react";
 | 
					import { useMemo } from "react";
 | 
				
			||||||
import { MRT_ColumnDef, MRT_RowData } from "mantine-react-table";
 | 
					import { MRT_ColumnDef, MRT_RowData } from "mantine-react-table";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const useShippingTableColumns = <T extends MRT_RowData>() => {
 | 
					type Props = {
 | 
				
			||||||
 | 
					    isBox: boolean;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const useShippingTableColumns = <T extends MRT_RowData>({ isBox }: Props) => {
 | 
				
			||||||
 | 
					    const hideBoxColumns = ["id"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return useMemo<MRT_ColumnDef<T>[]>(
 | 
					    return useMemo<MRT_ColumnDef<T>[]>(
 | 
				
			||||||
        () => [
 | 
					        () => [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                header: "ID",
 | 
				
			||||||
 | 
					                accessorKey: "id",
 | 
				
			||||||
 | 
					                Cell: ({ row }) => `K${row.original.id}`,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                header: "Название",
 | 
					                header: "Название",
 | 
				
			||||||
                accessorKey: "product.name",
 | 
					                accessorKey: "product.name",
 | 
				
			||||||
 | 
					                Cell: ({ row }) => row.original.product?.name ?? "-",
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                header: "Артикул",
 | 
					                header: "Артикул",
 | 
				
			||||||
                accessorKey: "product.article",
 | 
					                accessorKey: "product.article",
 | 
				
			||||||
 | 
					                Cell: ({ row }) => row.original.product?.article ?? "-",
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                header: "Размер",
 | 
					                header: "Размер",
 | 
				
			||||||
                accessorKey: "product.size",
 | 
					                accessorKey: "product.size",
 | 
				
			||||||
 | 
					                Cell: ({ row }) => row.original.product?.size ?? "-",
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                header: "Количество",
 | 
					                header: "Количество",
 | 
				
			||||||
@@ -22,6 +36,8 @@ const useShippingTableColumns = <T extends MRT_RowData>() => {
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
        [],
 | 
					        [],
 | 
				
			||||||
 | 
					    ).filter(
 | 
				
			||||||
 | 
					        columnDef => isBox || !hideBoxColumns.includes(columnDef.accessorKey || ""),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import { useDealPageContext } from "../../../contexts/DealPageContext.tsx";
 | 
					import { useDealPageContext } from "../../../contexts/DealPageContext.tsx";
 | 
				
			||||||
import { ShippingService } from "../../../../../client";
 | 
					import { CreateBoxInDealSchema, CreateBoxInPalletSchema, ShippingService } from "../../../../../client";
 | 
				
			||||||
import { notifications } from "../../../../../shared/lib/notifications.ts";
 | 
					import { notifications } from "../../../../../shared/lib/notifications.ts";
 | 
				
			||||||
import { modals } from "@mantine/modals";
 | 
					import { modals } from "@mantine/modals";
 | 
				
			||||||
import { Text } from "@mantine/core";
 | 
					import { Text } from "@mantine/core";
 | 
				
			||||||
@@ -45,23 +45,38 @@ const useShipping = () => {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const openShippingModal = (
 | 
					    const onCreateBox = (data: CreateBoxInPalletSchema | CreateBoxInDealSchema) => {
 | 
				
			||||||
        title: string,
 | 
					        ShippingService.updateBox({
 | 
				
			||||||
        isBox: boolean,
 | 
					            requestBody: {
 | 
				
			||||||
        palletId?: number,
 | 
					                data,
 | 
				
			||||||
        dealId?: number,
 | 
					            },
 | 
				
			||||||
    ) => {
 | 
					        })
 | 
				
			||||||
 | 
					            .then(({ ok, message }) => {
 | 
				
			||||||
 | 
					                notifications.guess(ok, { message });
 | 
				
			||||||
 | 
					                update();
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .catch(err => console.log(err));
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const onCreateBoxInDealClick = () => {
 | 
				
			||||||
 | 
					        onCreateBox({ dealId: deal?.id ?? -1 });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const onCreateBoxInPallet = (palletId: number) => {
 | 
				
			||||||
 | 
					        onCreateBox({ palletId });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const onCreateShippingProduct = (palletId: number) => {
 | 
				
			||||||
        if (!deal) return;
 | 
					        if (!deal) return;
 | 
				
			||||||
        modals.openContextModal({
 | 
					        modals.openContextModal({
 | 
				
			||||||
            modal: "shippingProductModal",
 | 
					            modal: "shippingProductModal",
 | 
				
			||||||
            title,
 | 
					            title: "Добавление товара на паллет",
 | 
				
			||||||
            withCloseButton: false,
 | 
					            withCloseButton: false,
 | 
				
			||||||
            innerProps: {
 | 
					            innerProps: {
 | 
				
			||||||
                deal,
 | 
					                deal,
 | 
				
			||||||
                updateOnSubmit: update,
 | 
					                updateOnSubmit: update,
 | 
				
			||||||
                isBox,
 | 
					                isBox: false,
 | 
				
			||||||
                shippingData: {
 | 
					                shippingData: {
 | 
				
			||||||
                    dealId,
 | 
					 | 
				
			||||||
                    palletId,
 | 
					                    palletId,
 | 
				
			||||||
                    productId: null,
 | 
					                    productId: null,
 | 
				
			||||||
                    quantity: null,
 | 
					                    quantity: null,
 | 
				
			||||||
@@ -70,31 +85,6 @@ const useShipping = () => {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const onCreateBoxInDealClick = () => {
 | 
					 | 
				
			||||||
        openShippingModal(
 | 
					 | 
				
			||||||
            "Добавление короба",
 | 
					 | 
				
			||||||
            true,
 | 
					 | 
				
			||||||
            undefined,
 | 
					 | 
				
			||||||
            deal?.id,
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const onCreateBoxInPallet = (palletId: number) => {
 | 
					 | 
				
			||||||
        openShippingModal(
 | 
					 | 
				
			||||||
            "Добавление короба",
 | 
					 | 
				
			||||||
            true,
 | 
					 | 
				
			||||||
            palletId,
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const onCreateShippingProduct = (palletId: number) => {
 | 
					 | 
				
			||||||
        openShippingModal(
 | 
					 | 
				
			||||||
            "Добавление товара на паллет",
 | 
					 | 
				
			||||||
            false,
 | 
					 | 
				
			||||||
            palletId,
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        onCreateBoxInDealClick,
 | 
					        onCreateBoxInDealClick,
 | 
				
			||||||
        onCreateBoxInPallet,
 | 
					        onCreateBoxInPallet,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,4 @@
 | 
				
			|||||||
import {
 | 
					import { CreateShippingProductSchema, UpdateBoxSchema, UpdateShippingProductSchema } from "../../../../../client";
 | 
				
			||||||
    CreateBoxInDealSchema,
 | 
					 | 
				
			||||||
    CreateBoxInPalletSchema,
 | 
					 | 
				
			||||||
    CreateShippingProductSchema,
 | 
					 | 
				
			||||||
    UpdateBoxSchema,
 | 
					 | 
				
			||||||
    UpdateShippingProductSchema,
 | 
					 | 
				
			||||||
} from "../../../../../client";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ShippingModalForm = {
 | 
					export type ShippingModalForm = {
 | 
				
			||||||
    quantity: number;
 | 
					    quantity: number;
 | 
				
			||||||
@@ -17,8 +11,6 @@ export type ShippingProductOption = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ShippingData =
 | 
					export type ShippingData =
 | 
				
			||||||
    CreateBoxInDealSchema
 | 
					    UpdateBoxSchema
 | 
				
			||||||
    | CreateBoxInPalletSchema
 | 
					 | 
				
			||||||
    | UpdateBoxSchema
 | 
					 | 
				
			||||||
    | CreateShippingProductSchema
 | 
					    | CreateShippingProductSchema
 | 
				
			||||||
    | UpdateShippingProductSchema;
 | 
					    | UpdateShippingProductSchema;
 | 
				
			||||||
@@ -16,7 +16,7 @@ const getRestProducts = ({
 | 
				
			|||||||
                             unaccountedValues,
 | 
					                             unaccountedValues,
 | 
				
			||||||
                         }: Props) => {
 | 
					                         }: Props) => {
 | 
				
			||||||
    const totalProducts = new Map(
 | 
					    const totalProducts = new Map(
 | 
				
			||||||
        deal?.products.map(product => [product.product.id, product]),
 | 
					        deal?.products.map(product => product && [product.product.id, product]),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const distributedProducts = new Map();
 | 
					    const distributedProducts = new Map();
 | 
				
			||||||
@@ -32,7 +32,7 @@ const getRestProducts = ({
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    deal?.boxes?.forEach((box) => {
 | 
					    deal?.boxes?.forEach((box) => {
 | 
				
			||||||
        if (box.id === unaccountedValues.boxId) return;
 | 
					        if (!box.product || box.id === unaccountedValues.boxId) return;
 | 
				
			||||||
        accountProduct(box.product, box.quantity);
 | 
					        accountProduct(box.product, box.quantity);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -42,7 +42,7 @@ const getRestProducts = ({
 | 
				
			|||||||
            accountProduct(shippingProduct.product, shippingProduct.quantity);
 | 
					            accountProduct(shippingProduct.product, shippingProduct.quantity);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        pallet.boxes.forEach((box) => {
 | 
					        pallet.boxes.forEach((box) => {
 | 
				
			||||||
            if (box.id === unaccountedValues.boxId) return;
 | 
					            if (!box.product || box.id === unaccountedValues.boxId) return;
 | 
				
			||||||
            accountProduct(box.product, box.quantity);
 | 
					            accountProduct(box.product, box.quantity);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user