import React, { useState, useEffect } from 'react';
import { Package, ShoppingCart, Users, TrendingUp, Camera, Send, LogOut, Eye, Edit, Trash2, Plus } from 'lucide-react';
const GarmentShopApp = () => {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [currentUser, setCurrentUser] = useState('');
const [currentTab, setCurrentTab] = useState('dashboard');
const [stockItems, setStockItems] = useState([]);
const [sales, setSales] = useState([]);
const [showAddStock, setShowAddStock] = useState(false);
const [showSaleModal, setShowSaleModal] = useState(false);
const [selectedItem, setSelectedItem] = useState(null);
// Stock form state
const [stockForm, setStockForm] = useState({
itemName: '',
category: '',
size: '',
color: '',
stockType: 'new',
quantity: '',
buyingPrice: '',
salePrice: '',
photo: null
});
// Sale form state
const [saleForm, setSaleForm] = useState({
itemId: '',
quantitySold: '',
soldPrice: '',
customerName: '',
customerMobile: ''
});
// Add stock item
const handleAddStock = () => {
if (!stockForm.itemName || !stockForm.category || !stockForm.size || !stockForm.color ||
!stockForm.quantity || !stockForm.buyingPrice || !stockForm.salePrice) {
alert('Please fill all required fields');
return;
}
const newItem = {
id: Date.now().toString(),
...stockForm,
dateAdded: new Date().toLocaleDateString('hi-IN'),
remainingQuantity: parseInt(stockForm.quantity)
};
setStockItems([...stockItems, newItem]);
setStockForm({
itemName: '',
category: '',
size: '',
color: '',
stockType: 'new',
quantity: '',
buyingPrice: '',
salePrice: '',
photo: null
});
setShowAddStock(false);
};
// Handle photo upload
const handlePhotoUpload = (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
setStockForm({...stockForm, photo: e.target.result});
};
reader.readAsDataURL(file);
}
};
// Add sale
const handleSale = () => {
if (!saleForm.quantitySold || !saleForm.soldPrice || !saleForm.customerName || !saleForm.customerMobile) {
alert('Please fill all required fields');
return;
}
const item = stockItems.find(item => item.id === saleForm.itemId);
if (!item || item.remainingQuantity < parseInt(saleForm.quantitySold)) {
alert('Insufficient stock!');
return;
}
if (saleForm.customerMobile.length !== 10) {
alert('Please enter a valid 10-digit mobile number');
return;
}
const newSale = {
id: Date.now().toString(),
...saleForm,
itemName: item.itemName,
date: new Date().toLocaleDateString('hi-IN'),
time: new Date().toLocaleTimeString('hi-IN'),
profit: (parseFloat(saleForm.soldPrice) - parseFloat(item.buyingPrice)) * parseInt(saleForm.quantitySold)
};
// Update stock
const updatedStock = stockItems.map(stockItem =>
stockItem.id === saleForm.itemId
? {...stockItem, remainingQuantity: stockItem.remainingQuantity - parseInt(saleForm.quantitySold)}
: stockItem
);
setStockItems(updatedStock);
setSales([...sales, newSale]);
// Generate WhatsApp receipt
generateWhatsAppReceipt(newSale, item);
setSaleForm({
itemId: '',
quantitySold: '',
soldPrice: '',
customerName: '',
customerMobile: ''
});
setShowSaleModal(false);
};
// Generate WhatsApp receipt
const generateWhatsAppReceipt = (sale, item) => {
const message = `🛍️ *${currentUser} Garments Receipt*\n\n` +
`📅 Date: ${sale.date}\n` +
`🕐 Time: ${sale.time}\n\n` +
`👤 Customer: ${sale.customerName}\n` +
`📱 Mobile: ${sale.customerMobile}\n\n` +
`📦 Item: ${sale.itemName}\n` +
`📏 Size: ${item.size}\n` +
`🎨 Color: ${item.color}\n` +
`🔢 Quantity: ${sale.quantitySold}\n` +
`💰 Price per piece: ₹${sale.soldPrice}\n` +
`💵 Total Amount: ₹${sale.soldPrice * sale.quantitySold}\n\n` +
`🙏 Thank you for shopping with us!\n` +
`For any queries: Contact us`;
const whatsappUrl = `https://wa.me/91${sale.customerMobile}?text=${encodeURIComponent(message)}`;
// Show the generated message first
alert(`WhatsApp Receipt Generated!\n\nMessage:\n${message}\n\nClick OK to open WhatsApp`);
// Open WhatsApp with pre-filled message
window.open(whatsappUrl, '_blank');
// Also show a demo of what will happen
console.log('WhatsApp URL:', whatsappUrl);
};
// Dashboard stats
const totalStock = stockItems.reduce((sum, item) => sum + item.remainingQuantity, 0);
const totalStockValue = stockItems.reduce((sum, item) => sum + (item.remainingQuantity * parseFloat(item.salePrice || 0)), 0);
const totalSales = sales.reduce((sum, sale) => sum + (parseFloat(sale.soldPrice) * parseInt(sale.quantitySold)), 0);
const totalProfit = sales.reduce((sum, sale) => sum + parseFloat(sale.profit || 0), 0);
if (!isLoggedIn) {
return (
Garment Shop Manager
Sign in to manage your inventory
);
}
return (
{/* Header */}
Garment Shop Manager
Welcome back, {currentUser}
{/* Sidebar */}
{/* Main Content */}
{currentTab === 'dashboard' && (
Dashboard
{/* WhatsApp Demo Button */}
📱 WhatsApp Receipt Demo
Test kar ke dekho ki WhatsApp receipt kaise kaam karta hai
{/* Stats Cards */}
Total Stock Items
{totalStock}
Stock Value
₹{totalStockValue.toLocaleString()}
Total Sales
₹{totalSales.toLocaleString()}
Total Profit
₹{totalProfit.toLocaleString()}
{/* Recent Activity */}
Recent Sales
{sales.length === 0 ? (
No sales recorded yet
) : (
{sales.slice(-5).reverse().map(sale => (
{sale.itemName}
{sale.customerName} • {sale.date}
₹{(sale.soldPrice * sale.quantitySold).toLocaleString()}
Profit: ₹{sale.profit}
))}
)}
)}
{currentTab === 'stock' && (
Stock Management
{/* Stock Items Grid */}
{stockItems.map(item => (
{item.photo && (

)}
{item.itemName}
{item.stockType}
Category: {item.category}
Size: {item.size}
Color: {item.color}
Remaining: {item.remainingQuantity}
Sale Price: ₹{item.salePrice}
))}
{stockItems.length === 0 && (
No stock items yet. Add your first item!
)}
)}
{currentTab === 'sales' && (
Sales History
{sales.length === 0 ? (
) : (
Date |
Item |
Customer |
Quantity |
Amount |
Profit |
{sales.map(sale => (
{sale.date}
|
{sale.itemName}
|
{sale.customerName}
{sale.customerMobile}
|
{sale.quantitySold}
|
₹{(sale.soldPrice * sale.quantitySold).toLocaleString()}
|
₹{sale.profit}
|
))}
)}
)}
{/* Add Stock Modal */}
{showAddStock && (
Add New Stock Item
setStockForm({...stockForm, itemName: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
setStockForm({...stockForm, size: e.target.value})}
placeholder="S, M, L, XL, 32, 34, etc."
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
setStockForm({...stockForm, color: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
setStockForm({...stockForm, quantity: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
setStockForm({...stockForm, buyingPrice: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
setStockForm({...stockForm, salePrice: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
)}
{/* Sale Modal */}
{showSaleModal && selectedItem && (
Make Sale
Item: {selectedItem.itemName} (Available: {selectedItem.remainingQuantity})
)}
);
};
export default GarmentShopApp;