unzip frontend

This commit is contained in:
2025-08-16 14:41:12 +02:00
parent b60af66732
commit 598774bca6
87 changed files with 9676 additions and 0 deletions
@@ -0,0 +1,114 @@
"use client"
import type React from "react"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
interface PurchaseFormProps {
supplierName: string
open: boolean
onOpenChange: (open: boolean) => void
onSubmit: (purchase: { amount: number; description: string; date: string; invoiceNumber: string }) => void
}
export function PurchaseForm({ supplierName, open, onOpenChange, onSubmit }: PurchaseFormProps) {
const [formData, setFormData] = useState({
amount: 0,
description: "",
date: new Date().toISOString().split("T")[0],
invoiceNumber: "",
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
onSubmit(formData)
onOpenChange(false)
setFormData({
amount: 0,
description: "",
date: new Date().toISOString().split("T")[0],
invoiceNumber: "",
})
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle>Add Purchase</DialogTitle>
<DialogDescription>Record a new purchase from {supplierName}</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="amount">Purchase Amount ($) *</Label>
<Input
id="amount"
type="number"
step="0.01"
min="0.01"
value={formData.amount}
onChange={(e) => setFormData({ ...formData, amount: Number.parseFloat(e.target.value) || 0 })}
placeholder="0.00"
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="invoiceNumber">Invoice Number</Label>
<Input
id="invoiceNumber"
value={formData.invoiceNumber}
onChange={(e) => setFormData({ ...formData, invoiceNumber: e.target.value })}
placeholder="INV-001"
/>
</div>
<div className="space-y-2">
<Label htmlFor="date">Purchase Date *</Label>
<Input
id="date"
type="date"
value={formData.date}
onChange={(e) => setFormData({ ...formData, date: e.target.value })}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="description">Description *</Label>
<Textarea
id="description"
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
placeholder="Describe what was purchased"
rows={3}
required
/>
</div>
<DialogFooter>
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit" disabled={formData.amount <= 0 || !formData.description.trim()}>
Add Purchase
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}
@@ -0,0 +1,196 @@
"use client"
import type React from "react"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import type { Supplier } from "@/types/business"
interface SupplierFormProps {
supplier?: Supplier
open: boolean
onOpenChange: (open: boolean) => void
onSubmit: (supplier: Omit<Supplier, "id">) => void
}
const paymentTerms = ["Net 15", "Net 30", "Net 45", "Net 60", "COD", "Prepaid", "Custom"]
export function SupplierForm({ supplier, open, onOpenChange, onSubmit }: SupplierFormProps) {
const [formData, setFormData] = useState({
name: supplier?.name || "",
email: supplier?.email || "",
phone: supplier?.phone || "",
address: supplier?.address || "",
paymentTerms: supplier?.paymentTerms || "Net 30",
notes: supplier?.notes || "",
contactPerson: supplier?.contactPerson || "",
businessType: supplier?.businessType || "",
taxId: supplier?.taxId || "",
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
onSubmit({
...formData,
amountOwed: supplier?.amountOwed || 0,
})
onOpenChange(false)
// Reset form if it's a new supplier
if (!supplier) {
setFormData({
name: "",
email: "",
phone: "",
address: "",
paymentTerms: "Net 30",
notes: "",
contactPerson: "",
businessType: "",
taxId: "",
})
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>{supplier ? "Edit Supplier" : "Add New Supplier"}</DialogTitle>
<DialogDescription>
{supplier ? "Update supplier information" : "Enter the details for the new supplier"}
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="name">Company Name *</Label>
<Input
id="name"
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
placeholder="Enter company name"
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="contactPerson">Contact Person</Label>
<Input
id="contactPerson"
value={formData.contactPerson}
onChange={(e) => setFormData({ ...formData, contactPerson: e.target.value })}
placeholder="Primary contact name"
/>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
value={formData.email}
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
placeholder="supplier@example.com"
/>
</div>
<div className="space-y-2">
<Label htmlFor="phone">Phone</Label>
<Input
id="phone"
value={formData.phone}
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
placeholder="(555) 123-4567"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="address">Address</Label>
<Textarea
id="address"
value={formData.address}
onChange={(e) => setFormData({ ...formData, address: e.target.value })}
placeholder="Company address"
rows={2}
/>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="businessType">Business Type</Label>
<Input
id="businessType"
value={formData.businessType}
onChange={(e) => setFormData({ ...formData, businessType: e.target.value })}
placeholder="e.g., Manufacturer, Distributor"
/>
</div>
<div className="space-y-2">
<Label htmlFor="taxId">Tax ID / VAT Number</Label>
<Input
id="taxId"
value={formData.taxId}
onChange={(e) => setFormData({ ...formData, taxId: e.target.value })}
placeholder="Tax identification number"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="paymentTerms">Payment Terms</Label>
<Select
value={formData.paymentTerms}
onValueChange={(value) => setFormData({ ...formData, paymentTerms: value })}
>
<SelectTrigger>
<SelectValue placeholder="Select payment terms" />
</SelectTrigger>
<SelectContent>
{paymentTerms.map((term) => (
<SelectItem key={term} value={term}>
{term}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="notes">Notes</Label>
<Textarea
id="notes"
value={formData.notes}
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
placeholder="Additional notes about this supplier"
rows={3}
/>
</div>
<DialogFooter>
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit">{supplier ? "Update Supplier" : "Add Supplier"}</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}
@@ -0,0 +1,162 @@
"use client"
import type React from "react"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
interface SupplierPaymentFormProps {
supplierName: string
amountOwed: number
open: boolean
onOpenChange: (open: boolean) => void
onSubmit: (payment: { amount: number; notes: string; date: string; paymentMethod: string }) => void
}
export function SupplierPaymentForm({
supplierName,
amountOwed,
open,
onOpenChange,
onSubmit,
}: SupplierPaymentFormProps) {
const [formData, setFormData] = useState({
amount: 0,
notes: "",
date: new Date().toISOString().split("T")[0],
paymentMethod: "",
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
onSubmit(formData)
onOpenChange(false)
setFormData({
amount: 0,
notes: "",
date: new Date().toISOString().split("T")[0],
paymentMethod: "",
})
}
const maxPayment = amountOwed
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle>Record Payment</DialogTitle>
<DialogDescription>Record a payment to {supplierName}</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="p-4 bg-muted rounded-lg">
<p className="text-sm text-muted-foreground mb-1">Amount Owed</p>
<p className="text-2xl font-bold">${amountOwed.toFixed(2)}</p>
</div>
<div className="space-y-2">
<Label htmlFor="amount">Payment Amount ($) *</Label>
<Input
id="amount"
type="number"
step="0.01"
min="0.01"
max={maxPayment}
value={formData.amount}
onChange={(e) => setFormData({ ...formData, amount: Number.parseFloat(e.target.value) || 0 })}
placeholder="0.00"
required
/>
<div className="flex gap-2">
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setFormData({ ...formData, amount: maxPayment / 4 })}
>
25%
</Button>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setFormData({ ...formData, amount: maxPayment / 2 })}
>
50%
</Button>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setFormData({ ...formData, amount: maxPayment })}
>
Full Amount
</Button>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="paymentMethod">Payment Method</Label>
<Input
id="paymentMethod"
value={formData.paymentMethod}
onChange={(e) => setFormData({ ...formData, paymentMethod: e.target.value })}
placeholder="e.g., Bank Transfer, Check, Cash"
/>
</div>
<div className="space-y-2">
<Label htmlFor="date">Payment Date *</Label>
<Input
id="date"
type="date"
value={formData.date}
onChange={(e) => setFormData({ ...formData, date: e.target.value })}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="notes">Notes</Label>
<Textarea
id="notes"
value={formData.notes}
onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
placeholder="Reference number, additional details, etc."
rows={3}
/>
</div>
{formData.amount > 0 && (
<div className="p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg">
<p className="text-sm text-green-800 dark:text-green-200">
New amount owed: <strong>${(amountOwed - formData.amount).toFixed(2)}</strong>
</p>
</div>
)}
<DialogFooter>
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit" disabled={formData.amount <= 0 || formData.amount > maxPayment}>
Record Payment
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}
@@ -0,0 +1,197 @@
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Badge } from "@/components/ui/badge"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Search, MoreHorizontal, Edit, Trash2, Mail, Phone, CreditCard, Plus } from "lucide-react"
import type { Supplier } from "@/types/business"
interface SuppliersTableProps {
suppliers: Supplier[]
onEdit: (supplier: Supplier) => void
onDelete: (supplierId: string) => void
onAddPurchase: (supplierId: string) => void
onRecordPayment: (supplierId: string) => void
}
export function SuppliersTable({ suppliers, onEdit, onDelete, onAddPurchase, onRecordPayment }: SuppliersTableProps) {
const [searchTerm, setSearchTerm] = useState("")
const [deleteSupplier, setDeleteSupplier] = useState<Supplier | null>(null)
const filteredSuppliers = suppliers.filter(
(supplier) =>
supplier.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
supplier.email.toLowerCase().includes(searchTerm.toLowerCase()) ||
supplier.contactPerson.toLowerCase().includes(searchTerm.toLowerCase()) ||
supplier.businessType.toLowerCase().includes(searchTerm.toLowerCase()),
)
const getPaymentStatus = (amountOwed: number) => {
if (amountOwed === 0) return { label: "Paid Up", variant: "default" as const, color: "text-green-600" }
if (amountOwed > 5000) return { label: "High Balance", variant: "secondary" as const, color: "text-red-600" }
return { label: "Outstanding", variant: "secondary" as const, color: "text-yellow-600" }
}
const handleDelete = (supplier: Supplier) => {
onDelete(supplier.id)
setDeleteSupplier(null)
}
return (
<div className="space-y-4">
{/* Search */}
<div className="relative">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4" />
<Input
placeholder="Search suppliers by name, email, contact person, or business type..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-10"
/>
</div>
{/* Suppliers Table */}
<div className="border rounded-lg overflow-hidden">
<Table>
<TableHeader>
<TableRow>
<TableHead>Supplier</TableHead>
<TableHead>Contact</TableHead>
<TableHead>Business Type</TableHead>
<TableHead>Payment Terms</TableHead>
<TableHead>Status</TableHead>
<TableHead>Amount Owed</TableHead>
<TableHead className="w-[50px]"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredSuppliers.length === 0 ? (
<TableRow>
<TableCell colSpan={7} className="text-center py-8 text-muted-foreground">
{searchTerm ? "No suppliers found matching your search." : "No suppliers added yet."}
</TableCell>
</TableRow>
) : (
filteredSuppliers.map((supplier) => {
const paymentStatus = getPaymentStatus(supplier.amountOwed)
return (
<TableRow key={supplier.id}>
<TableCell>
<div>
<p className="font-medium">{supplier.name}</p>
{supplier.contactPerson && (
<p className="text-sm text-muted-foreground">{supplier.contactPerson}</p>
)}
</div>
</TableCell>
<TableCell>
<div className="space-y-1">
{supplier.email && (
<div className="flex items-center gap-1 text-sm">
<Mail className="h-3 w-3" />
<span className="truncate max-w-[150px]">{supplier.email}</span>
</div>
)}
{supplier.phone && (
<div className="flex items-center gap-1 text-sm">
<Phone className="h-3 w-3" />
<span>{supplier.phone}</span>
</div>
)}
</div>
</TableCell>
<TableCell>
<span className="text-sm">{supplier.businessType || "N/A"}</span>
</TableCell>
<TableCell>
<Badge variant="outline" className="text-xs">
{supplier.paymentTerms}
</Badge>
</TableCell>
<TableCell>
<Badge variant={paymentStatus.variant} className="text-xs">
{paymentStatus.label}
</Badge>
</TableCell>
<TableCell>
<div className="text-right">
<p className={`font-medium text-sm ${supplier.amountOwed > 0 ? paymentStatus.color : ""}`}>
${supplier.amountOwed.toFixed(2)}
</p>
</div>
</TableCell>
<TableCell>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm">
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => onEdit(supplier)}>
<Edit className="h-4 w-4 mr-2" />
Edit
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onAddPurchase(supplier.id)}>
<Plus className="h-4 w-4 mr-2" />
Add Purchase
</DropdownMenuItem>
{supplier.amountOwed > 0 && (
<DropdownMenuItem onClick={() => onRecordPayment(supplier.id)}>
<CreditCard className="h-4 w-4 mr-2" />
Record Payment
</DropdownMenuItem>
)}
<DropdownMenuItem onClick={() => setDeleteSupplier(supplier)} className="text-red-600">
<Trash2 className="h-4 w-4 mr-2" />
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
)
})
)}
</TableBody>
</Table>
</div>
{/* Delete Confirmation Dialog */}
<AlertDialog open={!!deleteSupplier} onOpenChange={() => setDeleteSupplier(null)}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Supplier</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete "{deleteSupplier?.name}"? This action cannot be undone and will remove all
associated purchase history.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={() => deleteSupplier && handleDelete(deleteSupplier)}
className="bg-red-600 hover:bg-red-700"
>
Delete
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}