diff --git a/apps/edr-freight-web/backoffice/src/components/invoices/EimsFilingCard.tsx b/apps/edr-freight-web/backoffice/src/components/invoices/EimsFilingCard.tsx index ba507513c..c668c0570 100644 --- a/apps/edr-freight-web/backoffice/src/components/invoices/EimsFilingCard.tsx +++ b/apps/edr-freight-web/backoffice/src/components/invoices/EimsFilingCard.tsx @@ -1,11 +1,30 @@ -import { Alert, Badge, Button, Card, Group, SimpleGrid, Stack, Text } from "@mantine/core"; +import { useState } from "react"; +import { + Alert, + Badge, + Button, + Card, + Group, + Modal, + NumberInput, + Radio, + Select, + SimpleGrid, + Stack, + Table, + Text, + Textarea, + TextInput, +} from "@mantine/core"; import { useMutation, useQuery } from "@tanstack/react-query"; -import { AlertTriangle, RefreshCw, Send, ShieldCheck } from "lucide-react"; +import { AlertTriangle, Ban, Download, FileText, RefreshCw, Send, ShieldCheck } from "lucide-react"; import { useAuth } from "@/auth/useAuth"; import { FREIGHT_PERMS, hasPermission } from "@/lib/permissions"; import { api } from "@/services/api"; -import type { EimsInvoiceStatus } from "@/types/eims"; +import { eimsService } from "@/services/eims.service"; +import { openPdfBlob } from "@/components/warehouses/pdf"; +import { EIMS_MODE_OF_PAYMENT, type EimsInvoiceStatus, type EimsModeOfPayment } from "@/types/eims"; import { useToast } from "@/hooks/use-toast"; const STATUS_COLOR: Record = { @@ -14,6 +33,7 @@ const STATUS_COLOR: Record = { REGISTERED: "edr-green", FAILED: "red", UNKNOWN: "orange", + CANCELLED: "gray", }; const STATUS_LABEL: Record = { @@ -22,6 +42,7 @@ const STATUS_LABEL: Record = { REGISTERED: "Filed", FAILED: "Rejected", UNKNOWN: "Unacknowledged", + CANCELLED: "Cancelled", }; function Field({ label, value }: { label: string; value?: string | number | null }) { @@ -37,6 +58,367 @@ function Field({ label, value }: { label: string; value?: string | number | null ); } +/** Reason codes from the collection docs, e.g. "1" (Duplicate), "6" (Calculation Error). */ +const CANCEL_REASON_CODES = [ + { value: "1", label: "1 — Duplicate" }, + { value: "2", label: "2 — Buyer request" }, + { value: "3", label: "3 — Data entry error" }, + { value: "6", label: "6 — Calculation error" }, +]; + +function CancelModal({ + invoiceId, + opened, + onClose, +}: { + invoiceId: string; + opened: boolean; + onClose: () => void; +}) { + const { toast } = useToast(); + const [reasonCode, setReasonCode] = useState(null); + const [remark, setRemark] = useState(""); + + const cancel = useMutation( + api.invoices.eimsCancel.mutationOptions({ + onSuccess: () => { + onClose(); + toast({ title: "Cancelled with MoR" }); + }, + onError: (error) => toast({ title: "Could not cancel", description: error.message, variant: "destructive" }), + }), + ); + + return ( + + + + Cancels this invoice's registered document at MoR. Irreversible — an already-cancelled + invoice refuses a second attempt. + +