void, unvoid added
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
TrendingUp,
|
TrendingUp,
|
||||||
ThumbsDown,
|
ThumbsDown,
|
||||||
DollarSign,
|
DollarSign,
|
||||||
|
Ban,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { apiRequest, queryClient } from "@/lib/queryClient";
|
import { apiRequest, queryClient } from "@/lib/queryClient";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
@@ -35,7 +36,6 @@ import { Checkbox } from "@/components/ui/checkbox";
|
|||||||
import { DeleteConfirmationDialog } from "../ui/deleteDialog";
|
import { DeleteConfirmationDialog } from "../ui/deleteDialog";
|
||||||
import LoadingScreen from "../ui/LoadingScreen";
|
import LoadingScreen from "../ui/LoadingScreen";
|
||||||
import {
|
import {
|
||||||
ClaimStatus,
|
|
||||||
NewTransactionPayload,
|
NewTransactionPayload,
|
||||||
PaymentStatus,
|
PaymentStatus,
|
||||||
PaymentWithExtras,
|
PaymentWithExtras,
|
||||||
@@ -321,6 +321,36 @@ export default function PaymentsRecentTable({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//VOID and UNVOID Feature
|
||||||
|
const handleVoid = (paymentId: number) => {
|
||||||
|
updatePaymentStatusMutation.mutate({ paymentId, status: "VOID" });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUnvoid = (paymentId: number) => {
|
||||||
|
updatePaymentStatusMutation.mutate({ paymentId, status: "PENDING" });
|
||||||
|
};
|
||||||
|
|
||||||
|
const [isVoidOpen, setIsVoidOpen] = useState(false);
|
||||||
|
const [voidPaymentId, setVoidPaymentId] = useState<number | null>(null);
|
||||||
|
|
||||||
|
const [isUnvoidOpen, setIsUnvoidOpen] = useState(false);
|
||||||
|
const [unvoidPaymentId, setUnvoidPaymentId] = useState<number | null>(null);
|
||||||
|
|
||||||
|
const handleConfirmVoid = () => {
|
||||||
|
if (!voidPaymentId) return;
|
||||||
|
handleVoid(voidPaymentId);
|
||||||
|
setVoidPaymentId(null);
|
||||||
|
setIsVoidOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConfirmUnvoid = () => {
|
||||||
|
if (!unvoidPaymentId) return;
|
||||||
|
handleUnvoid(unvoidPaymentId);
|
||||||
|
setUnvoidPaymentId(null);
|
||||||
|
setIsUnvoidOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pagination
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (onPageChange) onPageChange(currentPage);
|
if (onPageChange) onPageChange(currentPage);
|
||||||
}, [currentPage, onPageChange]);
|
}, [currentPage, onPageChange]);
|
||||||
@@ -401,6 +431,13 @@ export default function PaymentsRecentTable({
|
|||||||
color: "bg-red-100 text-red-800",
|
color: "bg-red-100 text-red-800",
|
||||||
icon: <ThumbsDown className="h-3 w-3 mr-1" />,
|
icon: <ThumbsDown className="h-3 w-3 mr-1" />,
|
||||||
};
|
};
|
||||||
|
case "VOID":
|
||||||
|
return {
|
||||||
|
label: "Void",
|
||||||
|
color: "bg-gray-100 text-gray-800",
|
||||||
|
icon: <Ban className="h-3 w-3 mr-1" />,
|
||||||
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
label: status
|
label: status
|
||||||
@@ -598,17 +635,36 @@ export default function PaymentsRecentTable({
|
|||||||
<Edit className="h-4 w-4" />
|
<Edit className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{/* Pay Full Due */}
|
|
||||||
{payment.status !== "PAID" && (
|
{/* When NOT PAID and NOT VOID → Pay in Full + Void */}
|
||||||
|
{payment.status !== "PAID" &&
|
||||||
|
payment.status !== "VOID" && (
|
||||||
|
<>
|
||||||
<Button
|
<Button
|
||||||
variant="warning"
|
variant="warning"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handlePayAbsoluteFullDue(payment.id)}
|
onClick={() =>
|
||||||
|
handlePayAbsoluteFullDue(payment.id)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Pay Full Due
|
Pay in Full
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
{/* NEW: Void */}
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setVoidPaymentId(payment.id);
|
||||||
|
setIsVoidOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Void
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{/* Revert Full Due */}
|
|
||||||
|
{/* When PAID → Revert */}
|
||||||
{payment.status === "PAID" && (
|
{payment.status === "PAID" && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -621,6 +677,20 @@ export default function PaymentsRecentTable({
|
|||||||
Revert Full Due
|
Revert Full Due
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* When VOID → Unvoid */}
|
||||||
|
{payment.status === "VOID" && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setUnvoidPaymentId(payment.id);
|
||||||
|
setIsUnvoidOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Unvoid
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -642,6 +712,28 @@ export default function PaymentsRecentTable({
|
|||||||
onCancel={() => setIsRevertOpen(false)}
|
onCancel={() => setIsRevertOpen(false)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* NEW: Void Confirmation Dialog */}
|
||||||
|
<ConfirmationDialog
|
||||||
|
isOpen={isVoidOpen}
|
||||||
|
title="Confirm Void"
|
||||||
|
message={`Mark this payment as VOID? It will be excluded from balances and Calculations.`}
|
||||||
|
confirmLabel="Void"
|
||||||
|
confirmColor="bg-gray-700 hover:bg-gray-800"
|
||||||
|
onConfirm={handleConfirmVoid}
|
||||||
|
onCancel={() => setIsVoidOpen(false)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* NEW: Unvoid Confirmation Dialog */}
|
||||||
|
<ConfirmationDialog
|
||||||
|
isOpen={isUnvoidOpen}
|
||||||
|
title="Confirm Unvoid"
|
||||||
|
message={`Restore this payment to a normal state (PENDING)?`}
|
||||||
|
confirmLabel="Unvoid"
|
||||||
|
confirmColor="bg-blue-600 hover:bg-blue-700"
|
||||||
|
onConfirm={handleConfirmUnvoid}
|
||||||
|
onCancel={() => setIsUnvoidOpen(false)}
|
||||||
|
/>
|
||||||
|
|
||||||
<DeleteConfirmationDialog
|
<DeleteConfirmationDialog
|
||||||
isOpen={isDeletePaymentOpen}
|
isOpen={isDeletePaymentOpen}
|
||||||
onConfirm={handleConfirmDeletePayment}
|
onConfirm={handleConfirmDeletePayment}
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ enum PaymentStatus {
|
|||||||
PAID
|
PAID
|
||||||
OVERPAID
|
OVERPAID
|
||||||
DENIED
|
DENIED
|
||||||
|
VOID
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PaymentMethod {
|
enum PaymentMethod {
|
||||||
|
|||||||
Reference in New Issue
Block a user