Add profit analysis modal and cost tracking for products

Introduces a Profit Analysis modal for products, allowing users to view profit, margin, and markup calculations based on cost per unit and pricing tiers. Adds cost per unit input to the product modal, updates product types, and integrates the analysis modal into the products page and product table. This enhances product management with profit tracking and analysis features.
This commit is contained in:
NotII
2025-08-26 20:52:38 +01:00
parent 4e155a378e
commit be746664c5
5 changed files with 336 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Edit, Trash, AlertTriangle, CheckCircle, AlertCircle } from "lucide-react";
import { Edit, Trash, AlertTriangle, CheckCircle, AlertCircle, Calculator } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Product } from "@/models/products";
import { Badge } from "@/components/ui/badge";
@@ -11,6 +11,7 @@ interface ProductTableProps {
onEdit: (product: Product) => void;
onDelete: (productId: string) => void;
onToggleEnabled: (productId: string, enabled: boolean) => void;
onProfitAnalysis?: (productId: string, productName: string) => void;
getCategoryNameById: (categoryId: string) => string;
}
@@ -20,6 +21,7 @@ const ProductTable = ({
onEdit,
onDelete,
onToggleEnabled,
onProfitAnalysis,
getCategoryNameById
}: ProductTableProps) => {
@@ -93,6 +95,17 @@ const ProductTable = ({
/>
</TableCell>
<TableCell className="text-right flex justify-end space-x-1">
{onProfitAnalysis && (
<Button
variant="ghost"
size="sm"
onClick={() => onProfitAnalysis(product._id as string, product.name)}
className="text-green-600 hover:text-green-700 hover:bg-green-50 dark:hover:bg-green-950/20"
title="Profit Analysis"
>
<Calculator className="h-4 w-4" />
</Button>
)}
<Button variant="ghost" size="sm" onClick={() => onEdit(product)}>
<Edit className="h-4 w-4" />
</Button>